diff --git a/composer.json b/composer.json index e96f21e..6770ccc 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "ramsey/uuid": "^3.4" }, "require-dev": { - "codeception/codeception": "~2.0" + "mockery/mockery": "0.9.*", + "phpunit/phpunit": "~4.0" }, "authors": [ { @@ -40,5 +41,10 @@ "Nikapps\\OrtcPhp\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "minimum-stability": "stable" } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..03b769a --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,24 @@ + + + + + ./tests/ + ./tests/TestCase.php + + + + + src + + + diff --git a/src/Models/Channel.php b/src/Models/Channel.php index 9b16c65..57451f7 100644 --- a/src/Models/Channel.php +++ b/src/Models/Channel.php @@ -3,10 +3,21 @@ class Channel { - const PERMISSION_WRITE = 'w'; const PERMISSION_READ = 'r'; + /** + * Construct + * + * @param string $name + * @param string $permission + */ + public function __construct($name = null, $permission = self::PERMISSION_READ) + { + $this->setName($name); + $this->setPermission($permission); + } + /** * name of channel * @@ -58,4 +69,14 @@ public function setPermission($permission) return $this; } + + /** + * To string returned name + * + * @return string + */ + public function __toString() + { + return $this->getName(); + } } diff --git a/tests/Models/ChannelTest.php b/tests/Models/ChannelTest.php new file mode 100644 index 0000000..747f9ce --- /dev/null +++ b/tests/Models/ChannelTest.php @@ -0,0 +1,35 @@ +assertEquals('NAME1', $channel1->getName()); + $this->assertEquals('r', $channel1->getPermission()); + + $channel2 = new Channel('NAME_2', Channel::PERMISSION_WRITE); + $this->assertEquals('NAME_2', $channel2->getName()); + $this->assertEquals('w', $channel2->getPermission()); + } + + public function testSetAndGetAttributes() + { + $channel = new Channel; + $this->assertEquals($channel, $channel->setName('channel_name')); + $this->assertEquals($channel, $channel->setPermission(Channel::PERMISSION_READ)); + + $this->assertEquals('channel_name', $channel->getName()); + $this->assertEquals('r', $channel->getPermission()); + } + + public function testToString() + { + $channel = new Channel('foobar'); + $this->assertEquals('foobar', (string) $channel); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..299b02d --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,13 @@ +