/** * @covers ::createFromArray */ public function testCreateFromArray() { $entityFactory = new EntityFactory(CarEntity::class); /** * @var CarEntity $carEntity */ $carEntity = $entityFactory->createFromArray(['id' => 'bb4250bc-8258-11e6-ae22-56b6b6499611', 'make' => 'Ford', 'model' => 'Model T', 'horsepower' => '20', 'doors' => 'TWO', 'released' => '1908-10-01', 'modified' => '2015-05-03 00:53:42', 'created' => '2015-05-03 00:53:42']); $this->assertFalse($carEntity->isAltered()); $this->assertSame(CarEntity::class, get_class($carEntity)); $this->assertSame('bb4250bc-8258-11e6-ae22-56b6b6499611', $carEntity->get('id')); $this->assertSame('Ford', $carEntity->get('make')); $this->assertSame('Model T', $carEntity->get('model')); $this->assertSame(20, $carEntity->get('horsepower')); $this->assertEquals(new \DateTime('1908-10-01'), $carEntity->get('released')); $this->assertEquals(new \DateTime('2015-05-03 00:53:42'), $carEntity->get('modified')); $this->assertEquals(new \DateTime('2015-05-03 00:53:42'), $carEntity->get('created')); }
/** * Creates an array of Entity objects from statement * * @param \PDOStatement $statement * * @return Entity[] Entities from statement */ protected function createEntitiesFromStatement(\PDOStatement $statement) : array { $entities = []; $entityFactory = new EntityFactory($this->entityClass); foreach ($statement as $row) { $entities[] = $entityFactory->createFromArray($row); } return $entities; }