Example #1
0
 public function setUp()
 {
     $this->pdo = new \PDO("mysql:host=127.0.0.1;dbname=tests", 'root', '');
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->pdo->exec('SET NAMES utf8');
     /**
      * Table cars; SQLCommand
      */
     $table = new CarTable($this->pdo);
     $this->carsSqlCommand = new SQLCommand($table->getTableName(), CarEntity::getColumns());
 }
Example #2
0
 /**
  * @covers ::update
  */
 public function testUpdate()
 {
     $carTable = new CarTable($this->pdo);
     $cars = $carTable->findAll();
     $this->assertCount(2, $cars);
     /**
      * Alter first car
      */
     $firstCar = $cars[0];
     $this->assertFalse($firstCar->isAltered());
     $firstCar->set('horsepower', 21);
     $this->assertTrue($firstCar->isAltered());
     $carTable->update($firstCar);
     /**
      * Alter second car
      */
     $secondCar = $cars[1];
     $this->assertFalse($secondCar->isAltered());
     $secondCar->set('horsepower', 41);
     $this->assertTrue($secondCar->isAltered());
     $carTable->update($secondCar);
     /**
      * Assert data set
      */
     $expectedCsvDataSet = new \PHPUnit_Extensions_Database_DataSet_CsvDataSet();
     $expectedCsvDataSet->addTable('cars', dirname(__FILE__) . '/../Fixture/cars_after-update.csv');
     $expectedDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($expectedCsvDataSet);
     $expectedDataSet->setExcludeColumnsForTable('cars', ['modified', 'created']);
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection());
     $dataSet->addTable('cars', 'SELECT * FROM `cars`');
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet);
     $dataSet->setExcludeColumnsForTable('cars', ['modified', 'created']);
     $this->assertDataSetsEqual($expectedDataSet, $dataSet);
 }
Example #3
0
 protected function index()
 {
     $this->view = '../tests/View/Cars/Fixture/index';
     $carTable = new CarTable($this->pdo);
     $this->set('cars', $carTable->findAll());
 }