Skip to content

Commit 019d095

Browse files
authored
Merge pull request #2 from rubyqorn/dev-socket-credentials
Dev socket credentials
2 parents c899529 + 87fb06c commit 019d095

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/vendor/
2+
composer.lock.json

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
"WebSocket\\": "src/"
1515
}
1616
},
17-
"require": {}
17+
"require": {
18+
"phpunit/phpunit": "^9.3"
19+
}
1820
}

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<testsuites>
2+
<testsuite name="Socket layer tests">
3+
<directory>./tests/unit/*</directory>
4+
<file>./tests/unit/SocketTest.php</file>
5+
<file>./tests/unit/SocketCredentialsTest.php</file>
6+
</testsuite>
7+
</testsuites>

src/Socket.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace WebSocket;
44

5+
use Websocket\Credential\ICredential;
6+
57
class Socket
68
{
79
protected ?ICredential $credential;
810

911
/**
1012
* DI of SocketCredentials
11-
* @param ICredential $credential
13+
* @param \Websocket\Credential\ICredential $credential
1214
* @return void
1315
*/
1416
public function setCredentials(ICredential $credential)

tests/unit/SocketCredentialsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use WebSocket\Credential\SocketCredentials;
5+
6+
class SocketCredentialsTest extends TestCase
7+
{
8+
public function testCredentialGetterReturnHost()
9+
{
10+
$credential = new SocketCredentials();
11+
12+
$this->assertInstanceOf(
13+
\WebSocket\Credential\ICredential::class,
14+
$credential
15+
);
16+
17+
$credential->setCredential('host', 'localhost');
18+
19+
$this->assertSame(
20+
$credential->getCredential('host'),
21+
'localhost'
22+
);
23+
}
24+
}

tests/unit/SocketTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use WebSocket\Credential\SocketCredentials;
5+
use WebSocket\Socket;
6+
7+
class SocketTest extends TestCase
8+
{
9+
public function testDIReturnSocketCredential()
10+
{
11+
$socket = new Socket();
12+
$socket->setCredentials(new SocketCredentials());
13+
14+
$this->assertInstanceOf(
15+
\WebSocket\Credential\SocketCredentials::class,
16+
$socket->getCredentials()
17+
);
18+
}
19+
}

0 commit comments

Comments
 (0)