Exemplo n.º 1
0
 /**
  * @test
  * @covers SlimApp\Db\DbTable::find
  * @uses SlimApp\HasRequiredParamsTrait
  * @param string $tableName
  * @param array $keyOperatorValueValueType
  * @param string $findResults 'noResults' if no results expected, 'results' otherwise
  * @param string $tableName
  * @param integer|string $value
  * @param null|string $key
  * @dataProvider provider_find_returns_false_when_data_not_present_in_database_data_otherwise
  */
 public function find_returns_false_when_data_not_present_in_database_data_otherwise($findResults, $tableName, $value, $key)
 {
     $config = (require __DIR__ . '/database-config-for-dbunit.php');
     $table = $this->getMockBuilder('SlimApp\\Db\\DbTable')->setConstructorArgs([$config])->getMockForAbstractClass();
     $dbTable = new \SebastianBergmann\PeekAndPoke\Proxy($table);
     // Set tablename manually (set in subclasses, not in abstract class...)
     $dbTable->tableName = $tableName;
     $results = $dbTable->find($value, $key);
     // Get data as array from dataset (xml seed file)
     $resources = $this->getTablesFromDataSet()[$tableName];
     // ie. users
     // Query array using a php linq
     $expected = \YaLinqo\Enumerable::from($resources)->where('$resources ==> $resources["' . $key . '"] == "' . (string) $value . '"')->toArray();
     $expected = array_values($expected);
     //die(var_dump($results, $expected));
     $this->assertEquals($expected, $results);
     if ('noResults' === $findResults) {
         $this->assertEmpty($results);
     }
 }