tests/Parser/ParserTest.php
/**
     * Test parse asserts with modifiers.
     *
     * @noinspection PhpPossiblePolymorphicInvocationInspection
     */
Test parse asserts with modifiers.
Test parse asserts with modifiers .
public function testParseAssertsWithModifiers()
    {
        $parser = new Parser();
        $parseContext = new ParseContext();
        $parseResult = $parser->parse(
            FilePath::parse('foo.webunit'),
            [
                'get https://example.com/',
                'assert-empty',
                'assert-empty!',
                'assert-contains~^ Foo',
                'assert-header!~^ Content-type: text/html',
            ],
            $parseContext,
        );
        $testSuite = $parseResult->getTestSuite();
        $testCases = $testSuite->getTestCases();
        $parseErrors = $parseResult->getParseErrors();
        self::assertSame(1, count($testCases));
        self::assertSame('https://example.com/', $testCases[0]->getUrl()->__toString());
        self::assertSame(5, count($testCases[0]->getAsserts()));
        self::assertInstanceOf(DefaultAssert::class, $testCases[0]->getAsserts()[0]);
        self::assertInstanceOf(AssertEmpty::class, $testCases[0]->getAsserts()[1]);
        self::assertTrue((new Modifiers())->equals($testCases[0]->getAsserts()[1]->getModifiers()));
        self::assertInstanceOf(AssertEmpty::class, $testCases[0]->getAsserts()[2]);
        self::assertTrue((new Modifiers(ModifiersInterface::NOT))->equals($testCases[0]->getAsserts()[2]->getModifiers()));
        self::assertInstanceOf(AssertContains::class, $testCases[0]->getAsserts()[3]);
        self::assertSame('Foo', $testCases[0]->getAsserts()[3]->getContent());
        self::assertTrue((new Modifiers(ModifiersInterface::CASE_INSENSITIVE | ModifiersInterface::REGEXP))->equals($testCases[0]->getAsserts()[3]->getModifiers()));
        self::assertInstanceOf(AssertHeader::class, $testCases[0]->getAsserts()[4]);
        self::assertSame('Content-type', $testCases[0]->getAsserts()[4]->getHeaderName());
        self::assertSame('text/html', $testCases[0]->getAsserts()[4]->getHeaderValue());
        self::assertTrue((new Modifiers(ModifiersInterface::CASE_INSENSITIVE | ModifiersInterface::REGEXP | ModifiersInterface::NOT))->equals($testCases[0]->getAsserts()[4]->getModifiers()));
        self::assertSame(0, count($parseErrors));
        self::assertTrue($parseResult->isSuccess());
    }
public function testParseAssertsWithModifiers ( ) { $ parser = new Parser ( ) ; $ parseContext = new ParseContext ( ) ; $ parseResult = $ parser -> parse ( FilePath :: parse ( 'foo.webunit' ) , [ 'get https://example.com/' , 'assert-empty' , 'assert-empty!' , 'assert-contains~^ Foo' , 'assert-header!~^ Content-type: text/html' , ] , $ parseContext , ) ; $ testSuite = $ parseResult -> getTestSuite ( ) ; $ testCases = $ testSuite -> getTestCases ( ) ; $ parseErrors = $ parseResult -> getParseErrors ( ) ; self :: assertSame ( 1 , count ( $ testCases ) ) ; self :: assertSame ( 'https://example.com/' , $ testCases [ 0 ] -> getUrl ( ) -> __toString ( ) ) ; self :: assertSame ( 5 , count ( $ testCases [ 0 ] -> getAsserts ( ) ) ) ; self :: assertInstanceOf ( DefaultAssert :: class , $ testCases [ 0 ] -> getAsserts ( ) [ 0 ] ) ; self :: assertInstanceOf ( AssertEmpty :: class , $ testCases [ 0 ] -> getAsserts ( ) [ 1 ] ) ; self :: assertTrue ( ( new Modifiers ( ) ) -> equals ( $ testCases [ 0 ] -> getAsserts ( ) [ 1 ] -> getModifiers ( ) ) ) ; self :: assertInstanceOf ( AssertEmpty :: class , $ testCases [ 0 ] -> getAsserts ( ) [ 2 ] ) ; self :: assertTrue ( ( new Modifiers ( ModifiersInterface :: NOT ) ) -> equals ( $ testCases [ 0 ] -> getAsserts ( ) [ 2 ] -> getModifiers ( ) ) ) ; self :: assertInstanceOf ( AssertContains :: class , $ testCases [ 0 ] -> getAsserts ( ) [ 3 ] ) ; self :: assertSame ( 'Foo' , $ testCases [ 0 ] -> getAsserts ( ) [ 3 ] -> getContent ( ) ) ; self :: assertTrue ( ( new Modifiers ( ModifiersInterface :: CASE_INSENSITIVE | ModifiersInterface :: REGEXP ) ) -> equals ( $ testCases [ 0 ] -> getAsserts ( ) [ 3 ] -> getModifiers ( ) ) ) ; self :: assertInstanceOf ( AssertHeader :: class , $ testCases [ 0 ] -> getAsserts ( ) [ 4 ] ) ; self :: assertSame ( 'Content-type' , $ testCases [ 0 ] -> getAsserts ( ) [ 4 ] -> getHeaderName ( ) ) ; self :: assertSame ( 'text/html' , $ testCases [ 0 ] -> getAsserts ( ) [ 4 ] -> getHeaderValue ( ) ) ; self :: assertTrue ( ( new Modifiers ( ModifiersInterface :: CASE_INSENSITIVE | ModifiersInterface :: REGEXP | ModifiersInterface :: NOT ) ) -> equals ( $ testCases [ 0 ] -> getAsserts ( ) [ 4 ] -> getModifiers ( ) ) ) ; self :: assertSame ( 0 , count ( $ parseErrors ) ) ; self :: assertTrue ( $ parseResult -> isSuccess ( ) ) ; }
Test parse asserts with modifiers.
Test parse asserts with modifiers .