Skip to content

Commit 1bdfa06

Browse files
committed
Added property class.
1 parent caef3c6 commit 1bdfa06

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.phar
2+
/vendor/
3+
composer.lock

composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@
1818
"require": {
1919
"simplesamlphp/simplesamlphp": "~1.0",
2020
"simplesamlphp/composer-module-installer": "~1.0"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^6"
24+
},
25+
"autoload-dev": {
26+
"classmap": ["lib/", "tests/lib/"]
2127
}
2228
}

phpunit.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
5+
>
6+
<testsuites>
7+
<testsuite name="drupalauth">
8+
<directory suffix="Test.php">tests/</directory>
9+
</testsuite>
10+
11+
</testsuites>
12+
13+
</phpunit>

tests/lib/Property.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: kirill
5+
* Date: 6/09/18
6+
* Time: 4:07 PM
7+
*/
8+
9+
class Property
10+
{
11+
protected $name;
12+
protected $value;
13+
14+
/**
15+
* Property constructor.
16+
*/
17+
public function __construct($name)
18+
{
19+
$this->name = $name;
20+
}
21+
22+
public function set($value)
23+
{
24+
$this->value = $value;
25+
}
26+
27+
28+
public function __get($name)
29+
{
30+
if ($this->name !== $name) {
31+
throw new \Exception('Property name mismatch.');
32+
}
33+
34+
return $this->value;
35+
}
36+
}

tests/lib/PropertyTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: kirill
5+
* Date: 6/09/18
6+
* Time: 4:09 PM
7+
*/
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
class PropertyTest extends TestCase
12+
{
13+
14+
public function testSet()
15+
{
16+
$property = new Property('test');
17+
$property->set('value');
18+
$this->assertEquals('value', $property->test);
19+
}
20+
21+
/**
22+
* @expectedException \Exception
23+
* @expectedExceptionMessage Property name mismatch.
24+
*/
25+
public function testBadName()
26+
{
27+
$property = new Property('test');
28+
$test = $property->bad_name;
29+
}
30+
31+
public function testName()
32+
{
33+
$property = new Property('test');
34+
$this->assertEquals(null, $property->test, 'Return value for proper name');
35+
}
36+
}

0 commit comments

Comments
 (0)