analyze(); // Then $this->assertEquals('simple-table', $result->tableName); $this->assertEquals(FullEntity::class, $result->classFqcn); } public function testFieldsAreAnalyzed(): void { // Given $entity = FullEntity::class; // When $result = (new EntityAnalyzer($entity))->analyze(); // Then $this->assertContainsEquals( new EntityField( name: 'intField', type: PrimitiveType::INTEGER, columnName: 'int-field', isIdField: false, readAccess: FieldAccess::GETTER ), $result->fields ); $this->assertContainsEquals( new EntityField( name: 'idField', type: PrimitiveType::INTEGER, columnName: 'renamed-id-field', isIdField: true, readAccess: FieldAccess::PUBLIC ), $result->fields ); } public function testIdFieldIsFound(): void { // Given $entity = FullEntity::class; // When $result = (new EntityAnalyzer($entity))->analyze(); // Then $this->assertEquals( new EntityField( name: 'idField', type: PrimitiveType::INTEGER, columnName: 'renamed-id-field', isIdField: true, readAccess: FieldAccess::PUBLIC ), $result->idField ); } public function testNoIdIsInvalid(): void { // Given $entity = EntityWithoutId::class; // Then $this->expectException(InvalidEntity::class); // When (new EntityAnalyzer($entity))->analyze(); } public function testMultipleIdsIsInvalid(): void { // Given $entity = EntityWithTwoIds::class; // Then $this->expectException(InvalidEntity::class); // When (new EntityAnalyzer($entity))->analyze(); } public function testTableAttributeIsOptional(): void { // Given $entity = EntityWithoutTableAttribute::class; // When $result = (new EntityAnalyzer($entity))->analyze(); // Then $this->assertEquals("EntityWithoutTableAttribute", $result->tableName); } public function testArrayOfChildEntities(): void { // Given $entity = EntityWithListOfFullEntities::class; // When $result = (new EntityAnalyzer($entity))->analyze(); // Then $this->assertEquals( new EntityField( name: 'id', type: PrimitiveType::INTEGER, columnName: 'id', isIdField: true, readAccess: FieldAccess::PUBLIC ), $result->fields[0] ); $this->assertEquals( new EntityField( name: 'children', type: new ArrayType( new EntityResult( classFqcn: IdOnlyEntity::class, tableName: 'IdOnlyEntity', fields: [ new EntityField( name: 'id', type: PrimitiveType::INTEGER, columnName: 'id', isIdField: true, readAccess: FieldAccess::PUBLIC ) ], idField: new EntityField( name: 'id', type: PrimitiveType::INTEGER, columnName: 'id', isIdField: true, readAccess: FieldAccess::PUBLIC ) ) ), columnName: 'children', isIdField: false, readAccess: FieldAccess::PUBLIC ), $result->fields[1] ); } }