diff --git a/tests/DataSources/Users.php b/tests/DataSources/Users.php deleted file mode 100644 index 00826a9..0000000 --- a/tests/DataSources/Users.php +++ /dev/null @@ -1,19 +0,0 @@ - 'jwage'], - ['username' => 'ocramius'], - ]; - } -} diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 422fa4c..b14e185 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -4,19 +4,7 @@ namespace Doctrine\StaticWebsiteGenerator\Tests; -use Doctrine\Common\EventManager; -use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\RST\Parser as RSTParser; -use Doctrine\SkeletonMapper\DataSource\DataSourceObjectDataRepository; -use Doctrine\SkeletonMapper\Hydrator\BasicObjectHydrator; -use Doctrine\SkeletonMapper\Mapping\ClassMetadataFactory; -use Doctrine\SkeletonMapper\Mapping\ClassMetadataInstantiator; -use Doctrine\SkeletonMapper\ObjectFactory; -use Doctrine\SkeletonMapper\ObjectIdentityMap; -use Doctrine\SkeletonMapper\ObjectManager; -use Doctrine\SkeletonMapper\ObjectRepository\ObjectRepositoryFactory; -use Doctrine\SkeletonMapper\ObjectRepository\ObjectRepositoryInterface; -use Doctrine\SkeletonMapper\Persister\ObjectPersisterFactory; use Doctrine\StaticWebsiteGenerator\Controller\ControllerExecutor; use Doctrine\StaticWebsiteGenerator\Controller\ControllerProvider; use Doctrine\StaticWebsiteGenerator\Controller\ResponseFactory; @@ -35,7 +23,6 @@ use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFilesBuilder; use Doctrine\StaticWebsiteGenerator\Tests\Controllers\HomepageController; use Doctrine\StaticWebsiteGenerator\Tests\Controllers\UserController; -use Doctrine\StaticWebsiteGenerator\Tests\DataSources\Users; use Doctrine\StaticWebsiteGenerator\Tests\Models\User; use Doctrine\StaticWebsiteGenerator\Tests\Repositories\UserRepository; use Doctrine\StaticWebsiteGenerator\Tests\Requests\UserRequests; @@ -62,10 +49,10 @@ public function testBuild(): void $responseFactory = new ResponseFactory(); - $objectManager = $this->createObjectManager(); + $user1 = new User('jwage'); + $user2 = new User('ocramius'); - $userRepository = $objectManager->getRepository(User::class); - assert($userRepository instanceof UserRepository); + $userRepository = new UserRepository([$user1, $user2]); $controllerProvider = new ControllerProvider([ HomepageController::class => new HomepageController($userRepository, $responseFactory), @@ -186,44 +173,4 @@ private function getFileContents(string $buildDir, string $file): string return $contents; } - - private function createObjectManager(): ObjectManager - { - $objectRepositoryFactory = new ObjectRepositoryFactory(); - - $objectPersisterFactory = new ObjectPersisterFactory(); - - /** @var \Doctrine\Persistence\Mapping\ClassMetadataFactory> $classMetadataFactory */ - $classMetadataFactory = new ClassMetadataFactory( - new ClassMetadataInstantiator(), - ); - - $objectIdentityMap = new ObjectIdentityMap($objectRepositoryFactory); - - $eventManager = new EventManager(); - - $objectManager = new ObjectManager( - $objectRepositoryFactory, - $objectPersisterFactory, - $objectIdentityMap, - $classMetadataFactory, - $eventManager, - ); - - $objectFactory = new ObjectFactory(); - $objectHydrator = new BasicObjectHydrator($objectManager); - /** @var ObjectRepositoryInterface $userRepository */ - $userRepository = new UserRepository( - $objectManager, - new DataSourceObjectDataRepository($objectManager, new Users(), User::class), - $objectFactory, - $objectHydrator, - $eventManager, - User::class, - ); - - $objectRepositoryFactory->addObjectRepository(User::class, $userRepository); - - return $objectManager; - } } diff --git a/tests/Models/User.php b/tests/Models/User.php index d008a85..92a8252 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -4,24 +4,10 @@ namespace Doctrine\StaticWebsiteGenerator\Tests\Models; -use Doctrine\SkeletonMapper\Hydrator\HydratableInterface; -use Doctrine\SkeletonMapper\Mapping\ClassMetadataInterface; -use Doctrine\SkeletonMapper\Mapping\LoadMetadataInterface; -use Doctrine\SkeletonMapper\ObjectManagerInterface; - -class User implements HydratableInterface, LoadMetadataInterface +class User { - private string $username; - - public static function loadMetadata(ClassMetadataInterface $metadata): void - { - $metadata->setIdentifier(['username']); - } - - /** @param mixed[] $project */ - public function hydrate(array $project, ObjectManagerInterface $objectManager): void + public function __construct(private string $username) { - $this->username = (string) ($project['username'] ?? ''); } public function getUsername(): string diff --git a/tests/Repositories/UserRepository.php b/tests/Repositories/UserRepository.php index c4871ad..004a398 100644 --- a/tests/Repositories/UserRepository.php +++ b/tests/Repositories/UserRepository.php @@ -4,22 +4,35 @@ namespace Doctrine\StaticWebsiteGenerator\Tests\Repositories; -use Doctrine\SkeletonMapper\ObjectRepository\BasicObjectRepository; use Doctrine\StaticWebsiteGenerator\Tests\Models\User; +use function array_filter; +use function array_pop; use function assert; -/** - * @template T of User - * @template-extends BasicObjectRepository - */ -class UserRepository extends BasicObjectRepository +/** @template T of User */ +class UserRepository { + /** @param list $users */ + public function __construct(private array $users) + { + } + public function findOneByUsername(string $username): User { - $user = $this->findOneBy(['username' => $username]); + $users = array_filter($this->findAll(), static function (User $user) use ($username) { + return $user->getUsername() === $username; + }); + $user = array_pop($users); + assert($user instanceof User); return $user; } + + /** @return User[] */ + public function findAll(): array + { + return $this->users; + } }