This commit is contained in:
huangzhhui 2019-02-06 02:23:52 +08:00
parent b1c470447c
commit 2a80076951
8 changed files with 106 additions and 39 deletions

View File

@ -1,11 +1,19 @@
<?php <?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Event; namespace Hyperf\Event;
trait Stoppable trait Stoppable
{ {
/** /**
* @var bool * @var bool
*/ */
@ -30,5 +38,4 @@ trait Stoppable
$this->propagation = $propagation; $this->propagation = $propagation;
return $this; return $this;
} }
} }

View File

@ -1,7 +1,16 @@
<?php <?php
namespace HyperfTest\Event; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event;
use Hyperf\Event\ConfigProvider; use Hyperf\Event\ConfigProvider;
use Hyperf\Event\EventDispatcher; use Hyperf\Event\EventDispatcher;
@ -10,6 +19,10 @@ use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\ListenerProviderInterface; use Psr\EventDispatcher\ListenerProviderInterface;
/**
* @internal
* @coversNothing
*/
class ConfigProviderTest extends TestCase class ConfigProviderTest extends TestCase
{ {
public function testInvoke() public function testInvoke()
@ -26,6 +39,4 @@ class ConfigProviderTest extends TestCase
], ],
], (new ConfigProvider())()); ], (new ConfigProvider())());
} }
} }

View File

@ -1,14 +1,21 @@
<?php <?php
namespace HyperfTest\Event\Event; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event\Event;
use Hyperf\Event\Stoppable; use Hyperf\Event\Stoppable;
use Psr\EventDispatcher\StoppableEventInterface; use Psr\EventDispatcher\StoppableEventInterface;
class Alpha implements StoppableEventInterface class Alpha implements StoppableEventInterface
{ {
use Stoppable; use Stoppable;
} }

View File

@ -1,9 +1,17 @@
<?php <?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event\Event; namespace HyperfTest\Event\Event;
class Beta class Beta
{ {
} }

View File

@ -1,20 +1,31 @@
<?php <?php
namespace HyperfTest\Event; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event;
use Hyperf\Event\EventDispatcher; use Hyperf\Event\EventDispatcher;
use Hyperf\Event\ListenerProvider; use Hyperf\Event\ListenerProvider;
use HyperfTest\Event\Event\Alpha; use HyperfTest\Event\Event\Alpha;
use HyperfTest\Event\Event\Beta;
use HyperfTest\Event\Listener\AlphaListener; use HyperfTest\Event\Listener\AlphaListener;
use HyperfTest\Event\Listener\BetaListener; use HyperfTest\Event\Listener\BetaListener;
use Mockery; use Mockery;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\ListenerProviderInterface; use Psr\EventDispatcher\ListenerProviderInterface;
/**
* @internal
* @coversNothing
*/
class EventDispatcherTest extends TestCase class EventDispatcherTest extends TestCase
{ {
public function testInvokeDispatcher() public function testInvokeDispatcher()
@ -33,6 +44,4 @@ class EventDispatcherTest extends TestCase
$this->assertSame(2, $alphaListener->value); $this->assertSame(2, $alphaListener->value);
$this->assertSame(1, $betaListener->value); $this->assertSame(1, $betaListener->value);
} }
} }

View File

@ -1,14 +1,22 @@
<?php <?php
namespace HyperfTest\Event\Listener; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event\Listener;
use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Event\Contract\ListenerInterface;
use HyperfTest\Event\Event\Alpha; use HyperfTest\Event\Event\Alpha;
class AlphaListener implements ListenerInterface class AlphaListener implements ListenerInterface
{ {
public $value = 1; public $value = 1;
/** /**
@ -29,5 +37,4 @@ class AlphaListener implements ListenerInterface
{ {
$this->value = 2; $this->value = 2;
} }
} }

View File

@ -1,14 +1,22 @@
<?php <?php
namespace HyperfTest\Event\Listener; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event\Listener;
use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Event\Contract\ListenerInterface;
use HyperfTest\Event\Event\Beta; use HyperfTest\Event\Event\Beta;
class BetaListener implements ListenerInterface class BetaListener implements ListenerInterface
{ {
public $value = 1; public $value = 1;
/** /**
@ -29,5 +37,4 @@ class BetaListener implements ListenerInterface
{ {
$this->value = 2; $this->value = 2;
} }
} }

View File

@ -1,7 +1,16 @@
<?php <?php
namespace HyperfTest\Event; declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Event;
use Hyperf\Config\Config; use Hyperf\Config\Config;
use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\ConfigInterface;
@ -20,9 +29,12 @@ use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\ListenerProviderInterface; use Psr\EventDispatcher\ListenerProviderInterface;
use SplPriorityQueue; use SplPriorityQueue;
/**
* @internal
* @coversNothing
*/
class ListenerTest extends TestCase class ListenerTest extends TestCase
{ {
use MockeryPHPUnitIntegration; use MockeryPHPUnitIntegration;
public function testInvokeListenerProvider() public function testInvokeListenerProvider()
@ -74,7 +86,7 @@ class ListenerTest extends TestCase
'listeners' => [ 'listeners' => [
AlphaListener::class, AlphaListener::class,
BetaListener::class, BetaListener::class,
] ],
])); ]));
$container->shouldReceive('get') $container->shouldReceive('get')
->with(AlphaListener::class) ->with(AlphaListener::class)
@ -141,19 +153,18 @@ class ListenerTest extends TestCase
$this->assertSame(1, $listenerAnnotation->priority); $this->assertSame(1, $listenerAnnotation->priority);
// Define the priority. // Define the priority.
$listenerAnnotation = new ListenerAnnotation([ $listenerAnnotation = new ListenerAnnotation([
'priority' => 2 'priority' => 2,
]); ]);
$this->assertSame(2, $listenerAnnotation->priority); $this->assertSame(2, $listenerAnnotation->priority);
// String number // String number
$listenerAnnotation = new ListenerAnnotation([ $listenerAnnotation = new ListenerAnnotation([
'priority' => "2" 'priority' => '2',
]); ]);
$this->assertSame(2, $listenerAnnotation->priority); $this->assertSame(2, $listenerAnnotation->priority);
// Non-number // Non-number
$listenerAnnotation = new ListenerAnnotation([ $listenerAnnotation = new ListenerAnnotation([
'priority' => "string" 'priority' => 'string',
]); ]);
$this->assertSame(1, $listenerAnnotation->priority); $this->assertSame(1, $listenerAnnotation->priority);
} }
} }