getPdo()->exec( " CREATE TABLE SimpleEntity ( stringcol VARCHAR(250), intcol INTEGER PRIMARY KEY AUTOINCREMENT ); INSERT INTO SimpleEntity(stringcol, intcol) VALUES ('dings', 1), ('bumms', 2); " ); } #[Group('integration')] public function testCreatesNewEntity(): void { // Given $strategy = new SaveEntity(); $method = new RepositoryMethod( query: '', returnType: '', returnsNullable: true, returnListType: '', name: '', parameters: [ new RepositoryMethodParameter( name: '', type: SimpleEntity::class, function: ParameterFunction::STATEMENT_PARAMETER ) ], resolutionStrategy: $strategy ); $entity = new SimpleEntity(null, 'foobar'); $query = $method->createQuery([$entity]); // When $result = $query->execute($this->getPdo()); // Then $this->assertInstanceOf(SimpleEntity::class, $result); $this->assertNotNull($result->intcol); $this->assertNotSame($result, $entity); $stmt = $this->getPdo()->query("SELECT COUNT(*) c FROM SimpleEntity"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(3, $row['c'], 'Three rows expected'); } #[Group('integration')] public function testUpdatesEntity(): void { // Given $strategy = new SaveEntity(); $method = new RepositoryMethod( query: '', returnType: '', returnsNullable: true, returnListType: '', name: '', parameters: [ new RepositoryMethodParameter( name: '', type: SimpleEntity::class, function: ParameterFunction::STATEMENT_PARAMETER ) ], resolutionStrategy: $strategy ); $entity = new SimpleEntity(1, 'foobar'); $query = $method->createQuery([$entity]); // When $result = $query->execute($this->getPdo()); // Then $this->assertInstanceOf(SimpleEntity::class, $result); $this->assertNotSame($result, $entity); $this->assertEquals($entity, $result); $stmt = $this->getPdo()->query("SELECT COUNT(*) c FROM SimpleEntity"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(2, $row['c'], 'Three rows expected'); $stmt = $this->getPdo()->query('SELECT stringcol c FROM SimpleEntity WHERE intcol = 1'); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals('foobar', $row['c']); } }