| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace yiiunit\debug\router;
- use PHPUnit\Framework\TestCase;
- use yii\debug\models\router\CurrentRoute;
- use yii\log\Logger;
- class CurrentRouteTest extends TestCase
- {
- /**
- * @test
- */
- public function shouldDoNothingForNoMessages()
- {
- $router = new CurrentRoute();
- $this->assertSame([], $router->messages);
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertNull($router->message);
- $this->assertSame([], $router->logs);
- $this->assertSame(0, $router->count);
- $this->assertFalse($router->hasMatch);
- }
- /**
- * @test
- */
- public function shouldStoreMessageForProperOne()
- {
- $router = new CurrentRoute(['messages' => [['test', Logger::LEVEL_TRACE]]]);
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertSame('test', $router->message);
- $this->assertSame([], $router->logs);
- $this->assertSame(0, $router->count);
- $this->assertFalse($router->hasMatch);
- }
- /**
- * @test
- */
- public function shouldStoreLogForProperOneAndTrueMatch()
- {
- $router = new CurrentRoute(
- [
- 'messages' => [
- [
- ['rule' => 'test rule', 'match' => true],
- 999
- ]
- ]
- ]
- );
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertNull($router->message);
- $this->assertSame([['rule' => 'test rule', 'match' => true]], $router->logs);
- $this->assertSame(1, $router->count);
- $this->assertTrue($router->hasMatch);
- }
- /**
- * @test
- */
- public function shouldStoreLogForProperOneAndFalseMatch()
- {
- $router = new CurrentRoute(
- [
- 'messages' => [
- [
- ['rule' => 'test rule', 'match' => false],
- 999
- ]
- ]
- ]
- );
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertNull($router->message);
- $this->assertSame([['rule' => 'test rule', 'match' => false]], $router->logs);
- $this->assertSame(1, $router->count);
- $this->assertFalse($router->hasMatch);
- }
- /**
- * @test
- */
- public function shouldSkipParent()
- {
- $router = new CurrentRoute(
- [
- 'messages' => [
- [
- ['rule' => 'test rule', 'match' => false, 'parent' => 'test parent'],
- 999
- ],
- [
- ['rule' => 'test parent', 'match' => false],
- 999
- ]
- ]
- ]
- );
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertNull($router->message);
- $this->assertSame([['rule' => 'test rule', 'match' => false, 'parent' => 'test parent']], $router->logs);
- $this->assertSame(1, $router->count);
- $this->assertFalse($router->hasMatch);
- }
- /**
- * @test
- */
- public function shouldIncreaseCounter()
- {
- $router = new CurrentRoute(
- [
- 'messages' => [
- [
- ['rule' => 'test rule 1', 'match' => false],
- 999
- ],
- [
- ['rule' => 'test rule 2', 'match' => false],
- 999
- ]
- ]
- ]
- );
- $this->assertSame('', $router->route);
- $this->assertSame('', $router->action);
- $this->assertNull($router->message);
- $this->assertSame(
- [
- ['rule' => 'test rule 1', 'match' => false],
- ['rule' => 'test rule 2', 'match' => false]
- ],
- $router->logs
- );
- $this->assertSame(2, $router->count);
- $this->assertFalse($router->hasMatch);
- }
- }
|