当前位置: 首页>>代码示例>>PHP>>正文


PHP PyStringNode::getLines方法代码示例

本文整理汇总了PHP中Behat\Gherkin\Node\PyStringNode::getLines方法的典型用法代码示例。如果您正苦于以下问题:PHP PyStringNode::getLines方法的具体用法?PHP PyStringNode::getLines怎么用?PHP PyStringNode::getLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Behat\Gherkin\Node\PyStringNode的用法示例。


在下文中一共展示了PyStringNode::getLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportedFileOfShouldContain

 /**
  * @param string       $code
  * @param PyStringNode $csv
  *
  * @Then /^exported file of "([^"]*)" should contain:$/
  *
  * @throws ExpectationException
  * @throws \Exception
  */
 public function exportedFileOfShouldContain($code, PyStringNode $csv)
 {
     $config = $this->getFixturesContext()->getJobInstance($code)->getRawConfiguration();
     $path = $this->getMainContext()->getSubcontext('job')->getJobInstancePath($code);
     if (!is_file($path)) {
         throw $this->getMainContext()->createExpectationException(sprintf('File "%s" doesn\'t exist', $path));
     }
     $delimiter = isset($config['delimiter']) ? $config['delimiter'] : ';';
     $enclosure = isset($config['enclosure']) ? $config['enclosure'] : '"';
     $escape = isset($config['escape']) ? $config['escape'] : '\\';
     $csvFile = new \SplFileObject($path);
     $csvFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
     $csvFile->setCsvControl($delimiter, $enclosure, $escape);
     $expectedLines = [];
     foreach ($csv->getLines() as $line) {
         if (!empty($line)) {
             $expectedLines[] = explode($delimiter, str_replace($enclosure, '', $line));
         }
     }
     $actualLines = [];
     while ($data = $csvFile->fgetcsv()) {
         if (!empty($data)) {
             $actualLines[] = array_map(function ($item) use($enclosure) {
                 return str_replace($enclosure, '', $item);
             }, $data);
         }
     }
     $expectedCount = count($expectedLines);
     $actualCount = count($actualLines);
     assertSame($expectedCount, $actualCount, sprintf('Expecting to see %d rows, found %d', $expectedCount, $actualCount));
     if (md5(json_encode($actualLines[0])) !== md5(json_encode($expectedLines[0]))) {
         throw new \Exception(sprintf('Header in the file %s does not match expected one: %s', $path, implode(' | ', $actualLines[0])));
     }
     unset($actualLines[0]);
     unset($expectedLines[0]);
     foreach ($expectedLines as $expectedLine) {
         $originalExpectedLine = $expectedLine;
         $found = false;
         foreach ($actualLines as $index => $actualLine) {
             // Order of columns is not ensured
             // Sorting the line values allows to have two identical lines
             // with values in different orders
             sort($expectedLine);
             sort($actualLine);
             // Same thing for the rows
             // Order of the rows is not reliable
             // So we generate a hash for the current line and ensured that
             // the generated file contains a line with the same hash
             if (md5(json_encode($actualLine)) === md5(json_encode($expectedLine))) {
                 $found = true;
                 // Unset line to prevent comparing it twice
                 unset($actualLines[$index]);
                 break;
             }
         }
         if (!$found) {
             throw new \Exception(sprintf('Could not find a line containing "%s" in %s', implode(' | ', $originalExpectedLine), $path));
         }
     }
 }
开发者ID:SamirBoulil,项目名称:pim-community-dev,代码行数:69,代码来源:ExportProfilesContext.php

示例2: theConsoleOutputShouldHaveLinesEndingIn

 /**
  * @Then /^the console output should have lines ending in:$/
  */
 public function theConsoleOutputShouldHaveLinesEndingIn(PyStringNode $string)
 {
     $stdOutLines = explode(PHP_EOL, $this->lastBehatStdOut);
     $expectedLines = $string->getLines();
     \PHPUnit_Framework_Assert::assertCount(count($expectedLines), $stdOutLines);
     foreach ($stdOutLines as $idx => $stdOutLine) {
         $suffix = isset($expectedLines[$idx]) ? $expectedLines[$idx] : '(NONE)';
         $constraint = \PHPUnit_Framework_Assert::stringEndsWith($suffix);
         $constraint->evaluate($stdOutLine);
     }
 }
开发者ID:rbaarsma,项目名称:fastest,代码行数:14,代码来源:FeatureContext.php

示例3: iShouldSee

 /**
  * @Then /^I should see:$/
  */
 public function iShouldSee(PyStringNode $string)
 {
     $page = $this->session->getPage();
     $html = $page->getText();
     $lines = $string->getLines();
     foreach ($lines as $line) {
         if (strpos($html, $line) === false) {
             throw new Exception($line . ' not found on page');
         }
     }
 }
开发者ID:andrewnester,项目名称:simple-behat-google-by-example,代码行数:14,代码来源:FeatureContext.php

示例4: unpackFilesToTheSameDirectory

 /**
  * @Given /^Unpack files to the same directory:$/
  */
 public function unpackFilesToTheSameDirectory(PyStringNode $string)
 {
     $expectedFiles = $string->getLines();
     $this->pagesDir = $this->package->unpack($expectedFiles);
     assertFileExists($this->pagesDir);
     chdir($this->pagesDir);
     $foundFiles = array_flip(glob('*.html'));
     assertCount(count($expectedFiles), $foundFiles);
     foreach ($expectedFiles as $file) {
         assertArrayHasKey($file, $foundFiles);
     }
 }
开发者ID:martinsik,项目名称:php-doc-parser,代码行数:15,代码来源:PackageContext.php

示例5: getExpectedLines

 /**
  * @param PyStringNode $behatData
  * @param array        $config
  *
  * @return array
  */
 protected function getExpectedLines(PyStringNode $behatData, $config)
 {
     $delimiter = isset($config['delimiter']) ? $config['delimiter'] : ';';
     $enclosure = isset($config['enclosure']) ? $config['enclosure'] : '';
     $expectedLines = [];
     foreach ($behatData->getLines() as $line) {
         if (!empty($line)) {
             $expectedLines[] = explode($delimiter, str_replace($enclosure, '', $line));
         }
     }
     return $expectedLines;
 }
开发者ID:pierallard,项目名称:pim-community-dev,代码行数:18,代码来源:ImportExportContext.php

示例6: theFieldShouldHaveTheFollowingOptions

 /**
  * @param $fieldName
  * @param $string
  *
  * @throws ExpectationException
  *
  * @return bool
  *
  *
  * @Then /^the field "([^"]*)" should have the following options:$/
  */
 public function theFieldShouldHaveTheFollowingOptions($fieldName, PyStringNode $string)
 {
     $field = $this->getCurrentPage()->findField($fieldName);
     $id = $field->getAttribute('id');
     if ('select' === $field->getTagName()) {
         $options = $field->findAll('css', 'option');
     } elseif ('input' === $field->getTagName() && 0 === strpos($id, 's2id_')) {
         $options = $field->getParent()->getParent()->findAll('css', 'option');
     } else {
         throw $this->createExpectationException(sprintf('"%s" field is not a select field, can\'t have options.', $fieldName));
     }
     $availableOptions = [];
     foreach ($options as $option) {
         $optionValue = trim($option->getText());
         if ($optionValue) {
             $availableOptions[] = $optionValue;
         }
     }
     if (count(array_intersect($string->getLines(), $availableOptions)) === count($string->getLines())) {
         return true;
     }
     throw $this->createExpectationException(sprintf('"%s" field have these options (%s), but expected following options (%s).', $fieldName, implode(', ', $availableOptions), implode(', ', $string->getLines())));
 }
开发者ID:SamirBoulil,项目名称:pim-community-dev,代码行数:34,代码来源:AssertionContext.php

示例7: assertExistingHeaders

 /**
  * @Given /^the following response headers should be present:$/
  */
 public function assertExistingHeaders(PyStringNode $list)
 {
     $headers = $list->getLines();
     foreach ($headers as $header) {
         assertTrue($this->getLastResponse()->hasHeader($header), 'Header "' . $header . '" should be present');
     }
 }
开发者ID:ASP96,项目名称:imbo,代码行数:10,代码来源:RESTContext.php

示例8: stepThereAreTheFollowingRecords

 /**
  * Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.
  * 
  * Example: Given there are the following member records:
  *  member1:
  *    Email: member1@test.com
  *  member2:
  *    Email: member2@test.com
  * 
  * @Given /^there are the following ([^\s]*) records$/
  */
 public function stepThereAreTheFollowingRecords($dataObject, PyStringNode $string)
 {
     $yaml = array_merge(array($dataObject . ':'), $string->getLines());
     $yaml = implode("\n  ", $yaml);
     // Save fixtures into database
     // TODO Run prepareAsset() for each File and Folder record
     $yamlFixture = new \YamlFixture($yaml);
     $yamlFixture->writeInto($this->getFixtureFactory());
 }
开发者ID:jeffreyguo,项目名称:silverstripe-behat-extension,代码行数:20,代码来源:FixtureContext.php

示例9: convertPyStringToNormalString

 /**
  * Converts a PyStringObject to a normal stringObject with intents
  *
  * @param PyStringNode $pynode
  *
  * @return string
  */
 public function convertPyStringToNormalString(PyStringNode $pynode)
 {
     $intent = " ";
     $intentedPyNodeText = "";
     foreach ($pynode->getLines() as $pynodeLine) {
         $intentedPyNodeText .= $intent . $pynodeLine . "\n";
     }
     return sprintf("{$intent}\"\"\"\n%s{$intent}\"\"\"", $intentedPyNodeText);
 }
开发者ID:shell88,项目名称:bdd_videoannotator_php,代码行数:16,代码来源:BehatReportingAdapter.php

示例10: theAdapterShouldReportTheScenarioWithSteps

 /**
  * @Then /^the Adapter should report the scenario "([^"]*)" with following steps:$/
  */
 public function theAdapterShouldReportTheScenarioWithSteps($scenarioName, PyStringNode $expected_steps)
 {
     Phake::verify($this->_mockedClient, Phake::atLeast(1))->startScenario($scenarioName);
     // some steptext might be more than once in the result array
     $timesOccured = array_count_values($expected_steps->getLines());
     foreach ($expected_steps->getLines() as $steptext) {
         $times_expected = $timesOccured[$steptext];
         Phake::verify($this->_mockedClient, Phake::times($times_expected))->addStepToBuffer($steptext, null);
     }
     $this->_cntScenariosToBeStopped++;
     Phake::verify($this->_mockedClient, Phake::atLeast($this->_cntScenariosToBeStopped))->stopScenario();
 }
开发者ID:shell88,项目名称:bdd_videoannotator_php,代码行数:15,代码来源:BehatAdapterTestContext.php

示例11: aNewDocumentWith

 /**
  * @Given /^a new "([^"]*)" document with:$/
  */
 public function aNewDocumentWith($collection, PyStringNode $string)
 {
     $database = $this->mongoDatabase;
     $obj = json_decode(trim(implode($string->getLines())), true);
     $this->mongoClient->{$database}->{$collection}->insert($obj);
 }
开发者ID:jimbojsb,项目名称:behat-extras,代码行数:9,代码来源:MongoFixturesContext.php

示例12: getResult

 /**
  * @Then /^I should get:$/
  */
 public function getResult(PyStringNode $expected)
 {
     $tmp = substr($this->tmp, 0, -1);
     if (!function_exists('normalize')) {
         function normalize($str)
         {
             return str_replace('\\', '/', $str);
         }
     }
     // expected
     $lines = array_slice($expected->getLines(), 2);
     $expectedFiles = array_map(function ($line) {
         // remove everything before the filepath
         return normalize(trim(preg_replace('/\\d\\s*/', '', $line)));
     }, $lines);
     // actual
     $display = array_slice($this->display, 3);
     $actualFiles = array_map(function ($line) {
         // remove everything before the filepath
         return normalize(trim(preg_replace('/\\d\\s*/', '', $line)));
     }, $display);
     // compare
     if (0 === count($lines) && 0 !== count($display)) {
         throw new \Exception('Failed asserting that there are no suspects');
     }
     foreach ($expectedFiles as $expected) {
         if (false !== ($key = array_search($expected, $actualFiles))) {
             unset($actualFiles[$key]);
         } else {
             throw new \Exception(sprintf('Failed asserting that file "%s" is a suspect', $expected));
         }
     }
     if (0 !== count($actualFiles)) {
         throw new \Exception(sprintf('The file(s) "%s" are suspects too', implode('", "', $actualFiles)));
     }
 }
开发者ID:wouterj,项目名称:inspector,代码行数:39,代码来源:FeatureContext.php

示例13: applyTransformations

 /**
  * @Given /^I specify the following transformations:$/
  */
 public function applyTransformations(PyStringNode $transformations)
 {
     foreach ($transformations->getLines() as $t) {
         $this->client->getEventDispatcher()->addListener('request.before_send', function ($event) use($t) {
             $event['request']->getQuery()->add('t', $t);
         });
     }
 }
开发者ID:imbo,项目名称:imbo,代码行数:11,代码来源:ImboContext.php

示例14: iTestTheExposedResources

 /**
  * @Given /^I test the exposed resources:$/
  */
 public function iTestTheExposedResources(PyStringNode $resources)
 {
     foreach ($resources->getLines() as $line) {
         $this->getClient()->get($this->locatePath($line));
     }
 }
开发者ID:aleph-n,项目名称:opencholar,代码行数:9,代码来源:RestfulTrait.php

示例15: getJsonFromPyStringNode

 /**
  * treat payload as json data and try to decode it
  *
  * @var PyStringNode $node
  *
  * @return mixed
  */
 private function getJsonFromPyStringNode(PyStringNode $node)
 {
     return \GuzzleHttp\json_decode(implode('', $node->getLines()), true);
 }
开发者ID:thomblin,项目名称:bookmarks,代码行数:11,代码来源:FeatureContext.php


注:本文中的Behat\Gherkin\Node\PyStringNode::getLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。