Skip to content

Instantly share code, notes, and snippets.

@omerucel
Created September 20, 2015 08:58
Show Gist options
  • Save omerucel/24a9e9eef2561f256cda to your computer and use it in GitHub Desktop.
Save omerucel/24a9e9eef2561f256cda to your computer and use it in GitHub Desktop.
Table validate for behat tests
    /**
     * @Then /^"([^"]*)" tablosunda aşağıdaki kayıtlar bulunmalı:$/
     */
    public function tablosundaAsagidakiKayitlarBulunmali($arg1, \Behat\Gherkin\Node\TableNode $table)
    {
        $columns = implode(',', array_keys($table->getHash()[0]));
        $sql = 'SELECT ' . $columns . ' FROM ' . $arg1;
        $rows = $this->getDi()->getMySQLConnection()->fetchAll($sql);
        assertEquals(count($rows), count($table->getHash()));
        foreach ($rows as $index => $row) {
            foreach ($row as $key => $value) {
                $expectedValue = $table->getHash()[$index][$key];
                if (strpos($expectedValue, 'REGEX=') > -1) {
                    $regexPattern = str_replace('REGEX=', '', $expectedValue);
                    $regexPattern = '#' . $regexPattern . '#';
                    assertRegExp($regexPattern, $value);
                } else {
                    assertEquals($expectedValue, $value);
                }
            }
        }
    }
    And "invoice_charger_history" tablosunda aşağıdaki kayıtlar bulunmalı:
      | invoice_id | subs_id | charger_status_code | amount | charger_txn_id      |
      | 1          | 1       | -60001              | 14     | REGEX=.*            |
      | 1          | 1       | 1                   | 14     | TIMEOUT_BALANCE_FIX |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment