Skip to content

Commit

Permalink
Add test namespaces and simplify test bootstrap logic
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jul 18, 2019
1 parent 86586b6 commit 563cf67
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
}
],
"autoload": {
"psr-4": {"React\\Datagram\\": "src"}
"psr-4": {
"React\\Datagram\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"React\\Tests\\Datagram\\": "tests"
}
},
"require": {
"php": ">=5.3",
Expand Down
11 changes: 10 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="./tests/bootstrap.php">
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Datagram Test Suite">
<directory>./tests/</directory>
Expand Down
4 changes: 3 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace React\Tests\Datagram;

use React\Datagram\Socket;
use React\Datagram\Factory;
use Clue\React\Block;
Expand All @@ -13,7 +15,7 @@ class FactoryTest extends TestCase

public function setUp()
{
$this->loop = React\EventLoop\Factory::create();
$this->loop = \React\EventLoop\Factory::create();
$this->resolver = $this->createResolverMock();
$this->factory = new Factory($this->loop, $this->resolver);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/SocketTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace React\Tests\Datagram;

use React\Datagram\Socket;
use Clue\React\Block;

Expand All @@ -10,8 +12,8 @@ class SocketTest extends TestCase

public function setUp()
{
$this->loop = React\EventLoop\Factory::create();
$this->factory = new React\Datagram\Factory($this->loop, $this->createResolverMock());
$this->loop = \React\EventLoop\Factory::create();
$this->factory = new \React\Datagram\Factory($this->loop, $this->createResolverMock());
}

public function testCreateClientCloseWillNotBlock()
Expand Down
13 changes: 3 additions & 10 deletions tests/bootstrap.php → tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

require __DIR__ . '/../vendor/autoload.php';
namespace React\Tests\Datagram;

abstract class TestCase extends PHPUnit_Framework_TestCase
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function expectCallableOnce()
{
Expand All @@ -26,18 +26,11 @@ protected function expectCallableNever()

protected function createCallableMock()
{
return $this->getMockBuilder('CallableStub')->getMock();
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}

protected function createResolverMock()
{
return $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock();
}
}

class CallableStub
{
public function __invoke()
{
}
}

0 comments on commit 563cf67

Please sign in to comment.