|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 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($requestStack, array(403, 404, 405), Logger::WARNING); |
| 32 | + |
| 33 | + $this->assertEquals($expected, $strategy->isHandlerActivated($record)); |
| 34 | + } |
| 35 | + |
| 36 | + public function isActivatedProvider() |
| 37 | + { |
| 38 | + return array( |
| 39 | + array('/test', array('level' => Logger::ERROR), true), |
| 40 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(401)), true), |
| 41 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(402)), true), |
| 42 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(403)), false), |
| 43 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(404)), false), |
| 44 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(405)), false), |
| 45 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(406)), true), |
| 46 | + array('/foo', array('level' => Logger::ERROR, 'context' => $this->getContextException(500)), true), |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + protected function getContextException($code) |
| 51 | + { |
| 52 | + return array('exception' => new HttpException($code)); |
| 53 | + } |
| 54 | +} |
0 commit comments