/** * Method to test if the method update() works. * @since 0.0.1-dev * @test */ public function testSaveUpdate() { //The Team which will be deleted on database. $team = new Team(); $team->id = 2; $team->name = 'Example Team'; $team->tag = 'ET'; $team->website = 'http://example.com/esport'; //The TeamMapper to delete the Team on database. $teamMapper = new TeamMapper($this->pdo); $teamMapper->save($team); //Get the actual and expected table. $queryTable = $this->getConnection()->createQueryTable('team', 'SELECT * FROM team'); $expectedDataSet = __DIR__ . '/DataSets/Team/team-save-update.xml'; $expectedTable = $this->createXMLDataSet($expectedDataSet)->getTable('team'); //Check if the tables are equal. $this->assertTablesEqual($expectedTable, $queryTable); }
/** * Method to test the save method. * @since 1.0.0 * @test */ public function testSave() { //the Team Entity which will be created on database. $team_create = new Team(); $team_create->name = 'Example eSport'; $team_create->tag = 'EeS'; $team_create->website = 'http://example.com'; //the Team Entity which will be updated on database. $team_update = new Team(); $team_update->id = 2; $team_update->name = 'Example Team'; $team_update->tag = 'ET'; $team_update->website = 'http://example.com/esport'; //the TeamMapper to save the Team Entity (create) on database. $teamMapper = new TeamMapper($this->getConnection()->getConnection()); $teamMapper->save($team_create); //the TeamMapper to save the Team Entity (update) on database. $teamMapper = new TeamMapper($this->getConnection()->getConnection()); $teamMapper->save($team_update); //get the actual and expected table. $actualTable = $this->getConnection()->createQueryTable('team', 'SELECT * FROM team'); $expectedDataset = __DIR__ . '/DataSets/Team/team-save.xml'; $expectedTable = $this->createXMLDataSet($expectedDataset)->getTable('team'); //check whether the tables are equal. $this->assertTablesEqual($expectedTable, $actualTable); //the Clan Entity which should be fail. $clan = new Clan(); $clan->id = 0; $clan->name = 'Example Team'; $clan->tag = 'ET'; //another Entity than Team Entity is not valid on the TeamMapper (create). $this->assertFalse($teamMapper->save($clan)); //another Entity than Team Entity is not valid on the TeamMapper (update). $clan->id = 1; $this->assertFalse($teamMapper->save($clan)); }