testMetadata = $cept->getMetadata(); $this->scenario = new Codeception\Scenario($cept); $this->parser = new Parser($this->scenario, $this->testMetadata); } public function testParsingFeature() { $code = "wantTo('run this test'); "; $this->parser->parseFeature($code); $this->assertEquals('run this test', $this->scenario->getFeature()); $code = "wantToTest('this run'); "; $this->parser->parseFeature($code); $this->assertEquals('test this run', $this->scenario->getFeature()); } public function testParsingWithWhitespace() { $code = "wantTo( 'run this test' ); "; $this->parser->parseFeature($code); $this->assertEquals('run this test', $this->scenario->getFeature()); } public function testScenarioOptions() { $code = <<parser->parseScenarioOptions($code); $this->assertContains('davert', $this->testMetadata->getGroups()); $this->assertContains('windows', $this->testMetadata->getEnv()); } public function testCommentedInBlockScenarioOptions() { $code = <<parser->parseScenarioOptions($code); $this->assertTrue($this->testMetadata->isBlocked()); } public function testFeatureCommented() { $code = "wantTo('run this test'); "; $this->parser->parseFeature($code); $this->assertNull($this->scenario->getFeature()); $code = "wantTo('run this test'); \n */"; $this->parser->parseFeature($code); $this->assertNull($this->scenario->getFeature()); } public function testScenarioSkipOptionsHandled() { $code = "parser->parseScenarioOptions($code); $this->assertTrue($this->testMetadata->isBlocked()); } public function testScenarioIncompleteOptionHandled() { $code = "parser->parseScenarioOptions($code); $this->assertTrue($this->testMetadata->isBlocked()); } public function testSteps() { $code = file_get_contents(\Codeception\Configuration::projectDir().'tests/cli/UnitCept.php'); $this->assertContains('$I->seeInThisFile', $code); $this->parser->parseSteps($code); $text = $this->scenario->getText(); $this->assertContains("I see in this file", $text); } public function testStepsWithFriends() { $code = file_get_contents(\Codeception\Configuration::projectDir().'tests/web/FriendsCept.php'); $this->assertContains('$I->haveFriend', $code); $this->parser->parseSteps($code); $text = $this->scenario->getText(); $this->assertContains("jon does", $text); $this->assertContains("I have friend", $text); $this->assertContains("back to me", $text); } public function testParseFile() { $classes = Parser::getClassesFromFile(codecept_data_dir('SimpleTest.php')); $this->assertEquals(['SampleTest'], $classes); } public function testParseFileWithClass() { if (version_compare(PHP_VERSION, '5.5.0', '<')) { $this->markTestSkipped('only for php 5.5'); } $classes = Parser::getClassesFromFile(codecept_data_dir('php55Test')); $this->assertEquals(['php55Test'], $classes); } public function testParseFileWithAnonymousClass() { if (version_compare(PHP_VERSION, '7.0.0', '<')) { $this->markTestSkipped('only for php 7'); } $classes = Parser::getClassesFromFile(codecept_data_dir('php70Test')); $this->assertEquals(['php70Test'], $classes); } /* * https://github.com/Codeception/Codeception/issues/1779 */ public function testParseFileWhichUnsetsFileVariable() { $classes = Parser::getClassesFromFile(codecept_data_dir('unsetFile.php')); $this->assertEquals([], $classes); } /** * @group core * @throws \Codeception\Exception\TestParseException */ public function testModernValidation() { if (PHP_MAJOR_VERSION < 7) { $this->markTestSkipped(); } $this->setExpectedException('Codeception\Exception\TestParseException'); Parser::load(codecept_data_dir('Invalid.php')); } /** * @group core */ public function testClassesFromFile() { $classes = Parser::getClassesFromFile(codecept_data_dir('DummyClass.php')); $this->assertContains('DummyClass', $classes); $classes = Parser::getClassesFromFile(codecept_data_dir('SimpleWithDependencyInjectionCest.php')); $this->assertContains('simpleDI\\LoadedTestWithDependencyInjectionCest', $classes); $this->assertContains('simpleDI\\AnotherCest', $classes); } }