/** * @Then /^(?:the )?response should be:$/ */ public function theResponseShouldBe(PyStringNode $content) { if ($this->getResponseHeader('Content-Type') === 'application/json') { $this->assertJsonStringEqualsJsonString($this->adaptContent($content->getRaw()), $this->getResponse()->getContent(), sprintf('The content of the response is not the expected')); } else { Assertions::assertEquals($content->getRaw(), $this->getResponse()->getContent(), sprintf('The content of the response is not the expected')); } }
/** * @Then /^(?:the )?response should equal to json:$/ */ public function theResponseShouldEqualToJson(PyStringNode $jsonString) { $expected = json_decode($jsonString->getRaw(), true); $actual = $this->lastResponse; if (null === $expected) { throw new \RuntimeException("Can not convert etalon to json:\n" . $jsonString->getRaw()); } assertEquals($expected, $actual, "Failed asserting that equals to \n" . print_r($actual, true)); }
/** * @When I send a :method request to URL :url with body: */ public function iSendARequestToUrlWithBody($method, $url, PyStringNode $body) { $bodyReplace = $body->getRaw(); $bodyReplace = $this->replaceParameters($bodyReplace); $body = new PyStringNode([$bodyReplace], $body->getLine()); $this->restContext->iSendARequestToWithBody($method, $this->replaceParameters($url), $body); }
/** * @Then the system should have the following info sms subscription low balance reminder logs: * * @param PyStringNode $body */ public function theSystemShouldHaveTheFollowingOperations(PyStringNode $body) { /** @var CollectLogsTestWorker $collectLogsTestWorker */ $collectLogsTestWorker = $this->kernel->getContainer()->get('muchacuba.info_sms.subscription.low_balance_reminder.collect_logs_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectLogsTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\InfoSms\\Subscription\\LowBalanceReminder\\Log'); }
function it_saves_behat_feature_file(PyStringNode $config, Filesystem $filesystem) { $config->getRaw()->willReturn('Feature: test'); $filesystem->dumpFile(Argument::containingString('/features/feature.feature'), 'Feature: test')->shouldBeCalled(); $this->createWorkingDirectory(); $this->iHaveTheFeature($config); }
/** * @Given the system should have the following uniquenesses: */ public function theSystemShouldHaveTheFollowingUniquenesses(PyStringNode $body) { /** @var CollectUniquenessTestWorker $collectUniquenessTestWorker */ $collectUniquenessTestWorker = $this->kernel->getContainer()->get('cubalider.unique.collect_uniqueness_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectUniquenessTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Cubalider\\Uniqueness'); }
/** * @Given there exists a snippet template ":name" with the following property configuration */ public function thereExistsASnippetTemplateWithTheFollowingPropertyConfiguration($name, PyStringNode $string) { $template = <<<EOT <?xml version="1.0" ?> <template xmlns="http://schemas.sulu.io/template/template" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd" > <key>%s</key> <properties> <property name="title" type="text_line" mandatory="true"> <meta> <title lang="de">Title</title> <title lang="en">Title</title> </meta> </property> %s </properties> </template> EOT; $template = sprintf($template, $name, $string->getRaw()); $this->createStructureTemplate('snippet', $name, $template); }
/** * @Given the system should have the following internet profiles: * * @param PyStringNode $body * */ public function theSystemShouldHaveTheFollowingInternetProfiles(PyStringNode $body) { /** @var CollectProfilesTestWorker $collectProfilesTestWorker */ $collectProfilesTestWorker = $this->kernel->getContainer()->get('muchacuba.internet.collect_profiles_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectProfilesTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\Internet\\Profile'); }
/** * @Then I should get the following data: * * @param PyStringNode $string * * @throws \Exception */ public function iShouldGetTheFollowingData(PyStringNode $string) { $matcher = (new SimpleFactory())->createMatcher(); if (!$matcher->match(json_decode(json_encode($this->result), true), json_decode((string) $string->getRaw(), true))) { throw new \Exception($matcher->getError()); } }
/** * @Given the system should have the following recharge card profiles debt operations */ public function theSystemShouldHaveTheFollowingDebtOperations(PyStringNode $body) { /** @var CollectOperationsTestWorker $collectOperationsTestWorker */ $collectOperationsTestWorker = $this->kernel->getContainer()->get('muchacuba.recharge_card.profile.debt.collect_operations_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectOperationsTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\RechargeCard\\Profile\\Debt\\Operation'); }
/** * Sends a HTTP request with a body * * @Given I send a :method request to :url with body: */ public function iSendARequestToWithBody($method, $url, PyStringNode $body) { $client = $this->getSession()->getDriver()->getClient(); // intercept redirection $client->followRedirects(false); $client->request($method, $this->locatePath($url), array(), array(), array(), $body->getRaw()); $client->followRedirects(true); }
/** * @Then /^it should contain:$/ */ public function itShouldContain(PyStringNode $string) { $sql = file_get_contents($this->workingDirectory . '/behat_table.sql'); if (empty($sql) || !preg_match(sprintf('/%s/', preg_quote($string->getRaw())), $sql)) { $this->printDebug($sql); throw new Exception('Content not found'); } }
/** * @When the system has the following user accounts: * * @param PyStringNode $body */ public function theSystemHasTheFollowingUserAccounts(PyStringNode $body) { /** @var CreateAccountTestWorker $createAccountTestWorker */ $createAccountTestWorker = $this->kernel->getContainer()->get('muchacuba.user.create_account_test_worker'); $items = json_decode($body->getRaw(), true); foreach ($items as $item) { $createAccountTestWorker->create($item['id'], $item['username'], $item['password'], $item['roles']); } }
/** * @When /^I write a (?:spec|class) "([^"]*)" with following code$/ */ public function iWriteASpecWithFollowingCode($file, PyStringNode $codeContent) { $dirname = dirname($file); if (!file_exists($dirname)) { mkdir($dirname, 0777, true); } file_put_contents($file, $codeContent->getRaw()); require_once $file; }
/** @Then /^I should get:$/ */ public function iShouldGet(PyStringNode $string) { // if ((string) $string !== $this->output) { // throw new Exception( // "Actual output is:\n" . $this->output // ); // } assertEquals($string->getRaw(), $this->output); }
/** * @Then the system should have the following info sms message stats: * * @param PyStringNode $body */ public function theSystemShouldHaveTheFollowingStats(PyStringNode $body) { $expected = (array) json_decode($body->getRaw(), true); /** @var CollectStatsTestWorker $collectStatsTestWorker */ $collectStatsTestWorker = $this->kernel->getContainer()->get('muchacuba.info_sms.message.collect_stats_test_worker'); $actual = iterator_to_array($collectStatsTestWorker->collect()); (new SimpleFactory())->createMatcher()->match($actual, $expected) ?: (new \PHPUnit_Framework_Constraint_IsEqual($expected))->evaluate($actual); $this->rootContext->ignoreState('Muchacuba\\InfoSms\\Message\\Stat'); }
/** * @Then the JSON should match pattern: * * @param PyStringNode $string * @throws \Exception */ public function theJsonShouldMatchPattern(PyStringNode $string) { $expected = $string->getRaw(); $current = (string) $this->getParameterBag()->get('response')->getBody(); $matcher = (new SimpleFactory())->createMatcher(); if (!$matcher->match($current, $expected)) { throw new \Exception($matcher->getError()); } }
/** * @Given /^"([^"]*)" file have following content:$/ */ public function xmlFileHaveFollowingContent($fileName, PyStringNode $fileContent) { $targetFolder = sprintf("%s/Project/app/teryt", $this->fixturesPath); if (!file_exists($targetFolder)) { mkdir($targetFolder); } $filePath = sprintf("%s/%s", $targetFolder, $fileName); file_put_contents($filePath, $fileContent->getRaw()); expect(file_exists($filePath))->toBe(true); }
/** * @Given there are sections for :publicationId publication in API: * * @param string $publicationId * @param PyStringNode $sectionsFromApi */ public function thereAreSectionsForPublicationInAPI($publicationId, PyStringNode $sectionsFromApi) { $sectionsFromApiWithPublication = str_replace('PUBLICATION_ID', $publicationId, $sectionsFromApi->getRaw()); $sectionsApiResponse = json_decode($sectionsFromApiWithPublication, true); $this->sectionsFromApi[$publicationId] = $sectionsApiResponse['sections']; $path = sprintf(self::SECTION_PATH_PATTERN, $publicationId); $this->apiHttpClient->shouldReceive('get')->with(Mockery::on(function (ApiHttpPathAndQuery $apiHttpPathAndQuery) use($path) { return $apiHttpPathAndQuery == ApiHttpPathAndQuery::createForPath($path); }))->andReturn($sectionsFromApiWithPublication); }
public function testGetRaw() { $str = new PyStringNode(array('line1', 'line2', 'line3'), 0); $expected = <<<STR line1 line2 line3 STR; $this->assertEquals($expected, $str->getRaw()); }
/** * @Then this file body contains: */ public function thisFileBodyContains(PyStringNode $string) { $pattern = getcwd() . '/' . $this->dir; $content = ''; foreach ((new Finder())->files()->in($pattern)->name('*' . $this->fileName) as $file) { $content = $file->getContents(); } if (strpos($content, $string->getRaw()) === false) { throw new \Exception('File contains wrong data'); } }
/** * @Then the sitemap should have urls: */ public function theSitemapShouldHaveUrls(PyStringNode $string) { $xml = $this->getSession()->getPage()->getContent(); $crawler = new Crawler($xml); $assertUrls = explode("\n", $string->getRaw()); $foundUrls = []; foreach ($crawler->filter('url > loc') as $node) { $foundUrls[] = parse_url($node->nodeValue, PHP_URL_PATH); } if (count($diff = array_diff($assertUrls, $foundUrls)) > 0) { throw new \InvalidArgumentException(sprintf('Sitemap returned a difference: %s', json_encode(array_values($diff)))); } }
/** * @Given there is a file with: */ public function thereIsAFileWith(PyStringNode $string) { $file = uniqid() . ".php"; $container = $this->app->getContainer(); $generator = $container->get("Generator\\IndexGenerator"); $processor = $generator->getProcessor(); $processor->clearResultNodes(); $parser = $generator->getClassUtils()->getParser(); $parser->addProcessor($processor); $this->content = $string->getRaw(); $scope = $parser->parseContent($file, $this->content, null, false); $generator->processFileScope($this->project->getIndex(), $scope); }
/** * @Then there should be a message in queue :queue * * @param $queue * @param PyStringNode $string */ public function thereShouldBeAMessageInQueue($queue, PyStringNode $string = null) { $expected = $string ? $string->getRaw() : null; if (null === $expected) { $this->channel->basic_consume($queue); } else { $consumer = function (AMQPMessage $message) use($expected) { $this->channel->basic_ack($message->delivery_info['delivery_tag']); Assert::that($message->body)->equal($expected); }; $this->channel->basic_consume($queue, '', false, false, false, false, $consumer); } $this->channel->wait(null, false, 4); }
/** * @Given there exists a page template :arg1 with the following property configuration */ public function thereExistsAPageTemplateWithTheFollowingPropertyConfiguration($arg1, PyStringNode $string) { $template = <<<EOT <?xml version="1.0" ?> <template xmlns="http://schemas.sulu.io/template/template" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd" > <key>%s</key> <view>SuluTestBundle::content_test</view> <controller>SuluWebsiteBundle:Default:index</controller> <cacheLifetime>2400</cacheLifetime> <meta> <title lang="de">%s</title> <title lang="en">%s</title> </meta> <properties> <property name="title" type="text_line" mandatory="true"> <meta> <title lang="de">Tier</title> <title lang="en">Animals</title> </meta> <tag name="sulu.rlp.part"/> </property> <property name="url" type="resource_locator" mandatory="true"> <meta> <title lang="de">Adresse</title> <title lang="en">Resourcelocator</title> </meta> <tag name="sulu.rlp"/> </property> %s </properties> </template> EOT; $template = sprintf($template, $arg1, $arg1, $arg1, $string->getRaw()); $this->createStructureTemplate('page', $arg1, $template); }
/** * @param string $code * @param PyStringNode $yaml * * @Then /^exported yaml file of "([^"]*)" should contain:$/ * * @throws \Exception */ public function exportedYamlFileOfShouldContain($code, PyStringNode $yaml) { $path = $this->getExportedFile($code); $actualLines = Yaml::parse(file_get_contents($path)); $expectedLines = Yaml::parse($yaml->getRaw()); $isValidYamlFile = function ($expectedLines, $actualLines) use(&$isValidYamlFile) { foreach ($expectedLines as $key => $line) { $actualLine = $actualLines[$key]; if (is_array($line)) { $isValidYamlFile($line, $actualLine); } if ($line !== $actualLine) { throw new \Exception(sprintf('The exported file is not well formatted, expected %s, given %s', $line, $actualLine)); } } }; $isValidYamlFile($expectedLines, $actualLines); }
/** * @Then the response should contain json: */ public function theResponseShouldContainJson(PyStringNode $jsonString) { $etalon = json_decode($jsonString->getRaw(), true); $a = $this->getSession()->getPage(); // $b = $this->getSession()->getPage()->getHtml(); $c = $this->getSession()->getPage()->getContent(); $actual = json_decode($this->getMink()->getSession()->getPage()->getContent(), true); if (null === $etalon) { throw new \RuntimeException("Can not convert etalon to json:\n"); } Assertions::assertGreaterThanOrEqual(count($etalon), count($actual)); foreach ($etalon as $key => $needle) { Assertions::assertArrayHasKey($key, $actual); $e = $etalon[$key]; $g = $actual[$key]; Assertions::assertEquals($etalon[$key], $actual[$key]); } }
/** * @Then It should pass with: * * @param PyStringNode $string */ public function isExpectedSitemap(PyStringNode $string) { $sitemap = $this->app['sitemap']->generate(false); PHPUnit_Framework_Assert::assertEquals(preg_replace('/(\\s\\s+|\\t|\\n)/', '', $string->getRaw()), preg_replace('/(\\s\\s+|\\t|\\n)/', '', $sitemap)); }
/** * @Given the following logger settings: */ public function theFollowingLoggerSettings(PyStringNode $string) { $lines = preg_split("/\\r\\n|\\r|\\n/", $string->getRaw()); foreach ($lines as $key => $line) { $this->phpBinOptions .= '-d ' . $line . ' '; } }
/** * @Then /^I should see$/ */ public function iShouldSee(PyStringNode $string) { Assertions::assertEquals($string->getRaw(), $this->tester->getDisplay()); }