Skip to content

Commit

Permalink
Added construct method in class Channel
Browse files Browse the repository at this point in the history
Created test unit
  • Loading branch information
moura137 committed Jul 5, 2016
1 parent 7e58f6b commit 323bdea
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ramsey/uuid": "^3.4"
},
"require-dev": {
"codeception/codeception": "~2.0"
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0"
},
"authors": [
{
Expand All @@ -40,5 +41,10 @@
"Nikapps\\OrtcPhp\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "stable"
}
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/TestCase.php</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
23 changes: 22 additions & 1 deletion src/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -58,4 +69,14 @@ public function setPermission($permission)

return $this;
}

/**
* To string returned name
*
* @return string
*/
public function __toString()
{
return $this->getName();
}
}
35 changes: 35 additions & 0 deletions tests/Models/ChannelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Tests\Models;

use Tests\TestCase;
use Nikapps\OrtcPhp\Models\Channel;

class ChannelTest extends TestCase
{
public function testConstruct()
{
$channel1 = new Channel('NAME1');
$this->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);
}
}
13 changes: 13 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace Tests;

use Mockery;

class TestCase extends \PHPUnit_Framework_TestCase
{
public function tearDown()
{
parent::tearDown();
Mockery::close();
}
}

0 comments on commit 323bdea

Please sign in to comment.