|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bridge\Monolog\Tests\Handler\FingersCrossed; |
| 13 | + |
| 14 | +use Monolog\Logger; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy; |
| 17 | +use Symfony\Component\HttpFoundation\Request; |
| 18 | +use Symfony\Component\HttpFoundation\RequestStack; |
| 19 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
| 20 | + |
| 21 | +class HttpCodeActivationStrategyTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @dataProvider isActivatedProvider |
| 25 | + */ |
| 26 | + public function testIsActivated($url, $record, $expected) |
| 27 | + { |
| 28 | + $requestStack = new RequestStack(); |
| 29 | + $requestStack->push(Request::create($url)); |
| 30 | + |
| 31 | + $strategy = new HttpCodeActivationStrategy( |
| 32 | + $requestStack, |
| 33 | + array( |
| 34 | + array('code' => 403, 'url' => array()), |
| 35 | + array('code' => 404, 'url' => array()), |
| 36 | + array('code' => 405, 'url' => array()), |
| 37 | + array('code' => 400, 'url' => array('^/400/a', '^/400/b')), |
| 38 | + ), |
| 39 | + Logger::WARNING |
| 40 | + ); |
| 41 | + |
| 42 | + $this->assertEquals($expected, $strategy->isHandlerActivated($record)); |
| 43 | + } |
| 44 | + |
| 45 | + public function isActivatedProvider() |
| 46 | + { |
| 47 | + return array( |
| 48 | + array('/test', array('level' => Logger::ERROR), true), |
| 49 | + array('/400', array('level' => Logger::ERROR, 'context' => $this->getContextException(400)), true), |
| 50 | + array('/400/a', array('level' => Logger::ERROR, 'context' => $this->getContextException(400)), false), |
| 51 | + array('/400/b', array('level' => Logger::ERROR, 'context' => $this->getContextException(400)), false), |
| 52 | + array('/400/c', array('level' => Logger::ERROR, 'context' => $this->getContextException(400)), true), |
| 53 | + array('/401', array('level' => Logger::ERROR, 'context' => $this->getContextException(401)), true), |
| 54 | + array('/403', array('level' => Logger::ERROR, 'context' => $this->getContextException(403)), false), |
| 55 | + array('/404', array('level' => Logger::ERROR, 'context' => $this->getContextException(404)), false), |
| 56 | + array('/405', array('level' => Logger::ERROR, 'context' => $this->getContextException(405)), false), |
| 57 | + array('/500', array('level' => Logger::ERROR, 'context' => $this->getContextException(500)), true), |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + protected function getContextException($code) |
| 62 | + { |
| 63 | + return array('exception' => new HttpException($code)); |
| 64 | + } |
| 65 | +} |
0 commit comments