entityManager = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); $entityFactory = $this->getMockBuilder(EntityFactory::class)->disableOriginalConstructor()->getMock(); $this->mapper = $this->getMockBuilder(MysqlMapper::class)->disableOriginalConstructor()->getMock(); $entityManager ->method('getMapper') ->will($this->returnValue($this->mapper)); $entity = $this->seed = $this->createEntity('Test', Test::class); $this->collection = $this->getMockBuilder(EntityCollection::class)->disableOriginalConstructor()->getMock(); $entityFactory ->method('create') ->will($this->returnValue($entity)); $this->repository = new Repository('Test', $entityManager, $entityFactory); $entityManager ->method('getRepository') ->will($this->returnValue($this->repository)); } protected function createEntity(string $entityType, string $className) { return new $className($entityType, [], $this->entityManager); } public function testFind() { $params = [ 'whereClause' => [ 'name' => 'test', ], ]; $paramsExpected = [ 'whereClause' => [ 'name' => 'test', ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->find($params); } public function testFindOne() { $params = [ 'whereClause' => [ 'name' => 'test', ], ]; $paramsExpected = [ 'whereClause' => [ 'name' => 'test', ], 'offset' => 0, 'limit' => 1, ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->findOne($params); } public function testWhere1() { $paramsExpected = [ 'whereClause' => [ 'name' => 'test', ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->where(['name' => 'test'])->find(); } public function testWhere2() { $paramsExpected = [ 'whereClause' => [ ['name' => 'test'], ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->where('name', 'test')->find(); } public function testWhereFineOne() { $paramsExpected = [ 'whereClause' => [ ['name' => 'test'], ], 'offset' => 0, 'limit' => 1, ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->where('name', 'test')->findOne(); } public function testJoin1() { $paramsExpected = [ 'joins' => [ 'Test', ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->join('Test')->find(); } public function testJoin2() { $paramsExpected = [ 'joins' => [ 'Test1', 'Test2', ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->join(['Test1', 'Test2'])->find(); } public function testJoin3() { $paramsExpected = [ 'joins' => [ ['Test1', 'test1'], ['Test2', 'test2'], ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->join([['Test1', 'test1'], ['Test2', 'test2']])->find(); } public function testJoin4() { $paramsExpected = [ 'joins' => [ ['Test1', 'test1', ['k' => 'v']], ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->join('Test1', 'test1', ['k' => 'v'])->find(); } public function testLeftJoin1() { $paramsExpected = [ 'leftJoins' => [ 'Test', ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->leftJoin('Test')->find(); } public function testMultipleLeftJoins() { $paramsExpected = [ 'leftJoins' => [ 'Test1', ['Test2', 'test2'], ], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->leftJoin('Test1')->leftJoin('Test2', 'test2')->find(); } public function testDistinct() { $paramsExpected = [ 'distinct' => true, ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->distinct()->find(); } public function testSth() { $paramsExpected = [ 'returnSthCollection' => true, ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->sth()->find(); } public function testOrder1() { $paramsExpected = [ 'orderBy' => 'name', 'order' => 'ASC', ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->order('name')->find(); } public function testSelect() { $paramsExpected = [ 'select' => ['name', 'date'], ]; $this->mapper ->expects($this->once()) ->method('select') ->will($this->returnValue($this->collection)) ->with($this->seed, $paramsExpected); $this->repository->select(['name', 'date'])->find(); } }