4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\Tests\Parser\Handler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\CssSelector\Parser\Reader;
16 use Symfony\Component\CssSelector\Parser\Token;
17 use Symfony\Component\CssSelector\Parser\TokenStream;
20 * @author Jean-François Simon <contact@jfsimon.fr>
22 abstract class AbstractHandlerTest extends TestCase
24 /** @dataProvider getHandleValueTestData */
25 public function testHandleValue($value, Token $expectedToken, $remainingContent)
27 $reader = new Reader($value);
28 $stream = new TokenStream();
30 $this->assertTrue($this->generateHandler()->handle($reader, $stream));
31 $this->assertEquals($expectedToken, $stream->getNext());
32 $this->assertRemainingContent($reader, $remainingContent);
35 /** @dataProvider getDontHandleValueTestData */
36 public function testDontHandleValue($value)
38 $reader = new Reader($value);
39 $stream = new TokenStream();
41 $this->assertFalse($this->generateHandler()->handle($reader, $stream));
42 $this->assertStreamEmpty($stream);
43 $this->assertRemainingContent($reader, $value);
46 abstract public function getHandleValueTestData();
48 abstract public function getDontHandleValueTestData();
50 abstract protected function generateHandler();
52 protected function assertStreamEmpty(TokenStream $stream)
54 $property = new \ReflectionProperty($stream, 'tokens');
55 $property->setAccessible(true);
57 $this->assertEquals(array(), $property->getValue($stream));
60 protected function assertRemainingContent(Reader $reader, $remainingContent)
62 if ('' === $remainingContent) {
63 $this->assertEquals(0, $reader->getRemainingLength());
64 $this->assertTrue($reader->isEOF());
66 $this->assertEquals(\strlen($remainingContent), $reader->getRemainingLength());
67 $this->assertEquals(0, $reader->getOffset($remainingContent));