Skip to content

Commit 92f3483

Browse files
authored
Merge pull request #5 from soleon-leiloes/patch02
Added construct method in class Channel
2 parents 7e58f6b + 323bdea commit 92f3483

5 files changed

Lines changed: 101 additions & 2 deletions

File tree

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"ramsey/uuid": "^3.4"
2424
},
2525
"require-dev": {
26-
"codeception/codeception": "~2.0"
26+
"mockery/mockery": "0.9.*",
27+
"phpunit/phpunit": "~4.0"
2728
},
2829
"authors": [
2930
{
@@ -40,5 +41,10 @@
4041
"Nikapps\\OrtcPhp\\": "src/"
4142
}
4243
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Tests\\": "tests/"
47+
}
48+
},
4349
"minimum-stability": "stable"
4450
}

phpunit.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
<exclude>./tests/TestCase.php</exclude>
17+
</testsuite>
18+
</testsuites>
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">src</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>

src/Models/Channel.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33

44
class Channel
55
{
6-
76
const PERMISSION_WRITE = 'w';
87
const PERMISSION_READ = 'r';
98

9+
/**
10+
* Construct
11+
*
12+
* @param string $name
13+
* @param string $permission
14+
*/
15+
public function __construct($name = null, $permission = self::PERMISSION_READ)
16+
{
17+
$this->setName($name);
18+
$this->setPermission($permission);
19+
}
20+
1021
/**
1122
* name of channel
1223
*
@@ -58,4 +69,14 @@ public function setPermission($permission)
5869

5970
return $this;
6071
}
72+
73+
/**
74+
* To string returned name
75+
*
76+
* @return string
77+
*/
78+
public function __toString()
79+
{
80+
return $this->getName();
81+
}
6182
}

tests/Models/ChannelTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Tests\Models;
3+
4+
use Tests\TestCase;
5+
use Nikapps\OrtcPhp\Models\Channel;
6+
7+
class ChannelTest extends TestCase
8+
{
9+
public function testConstruct()
10+
{
11+
$channel1 = new Channel('NAME1');
12+
$this->assertEquals('NAME1', $channel1->getName());
13+
$this->assertEquals('r', $channel1->getPermission());
14+
15+
$channel2 = new Channel('NAME_2', Channel::PERMISSION_WRITE);
16+
$this->assertEquals('NAME_2', $channel2->getName());
17+
$this->assertEquals('w', $channel2->getPermission());
18+
}
19+
20+
public function testSetAndGetAttributes()
21+
{
22+
$channel = new Channel;
23+
$this->assertEquals($channel, $channel->setName('channel_name'));
24+
$this->assertEquals($channel, $channel->setPermission(Channel::PERMISSION_READ));
25+
26+
$this->assertEquals('channel_name', $channel->getName());
27+
$this->assertEquals('r', $channel->getPermission());
28+
}
29+
30+
public function testToString()
31+
{
32+
$channel = new Channel('foobar');
33+
$this->assertEquals('foobar', (string) $channel);
34+
}
35+
}

tests/TestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Tests;
3+
4+
use Mockery;
5+
6+
class TestCase extends \PHPUnit_Framework_TestCase
7+
{
8+
public function tearDown()
9+
{
10+
parent::tearDown();
11+
Mockery::close();
12+
}
13+
}

0 commit comments

Comments
 (0)