getSqlMock("default"); $serviceLocatorMock = $this->getServiceLocatorMock([ \common_persistence_Manager::SERVICE_ID => $managerMock, ]); $this->persistence = $managerMock->getPersistenceById("default"); $rdsHelper = new GenerateRdsDeliveryExecutionTable(); $rdsHelper->generateTable($this->persistence); $this->classUnderTest = $this ->getMockBuilder(RdsDeliveryExecutionService::class) ->setMethods(["getNewUri"]) ->getMock() ; $this->classUnderTest->setServiceLocator($serviceLocatorMock); $this->classUnderTest->method("getNewUri")->willReturn("test"); } public function tearDown(): void { $this->classUnderTest = null; } public function testClassMethods() { $this->assertTrue(method_exists($this->classUnderTest, "deleteDeliveryExecutionData")); $this->assertTrue(method_exists($this->classUnderTest, "getExecutionsByDelivery")); $this->assertTrue(method_exists($this->classUnderTest, "getUserExecutions")); $this->assertTrue(method_exists($this->classUnderTest, "getDeliveryExecutionsByStatus")); $this->assertTrue(method_exists($this->classUnderTest, "spawnDeliveryExecution")); $this->assertTrue(method_exists($this->classUnderTest, "initDeliveryExecution")); $this->assertTrue(method_exists($this->classUnderTest, "getDeliveryExecution")); } public function testClassContants() { $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::ID_PREFIX")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::TABLE_NAME")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_ID")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_DELIVERY_ID")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_USER_ID")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_STATUS")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_FINISHED_AT")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_STARTED_AT")); $this->assertTrue(defined(RdsDeliveryExecutionService::class . "::COLUMN_LABEL")); } public function testDeleteDeliveryExecutionData() { $deliveryExecutionMock = $this->prophesize(DeliveryExecution::class); $deliveryExecutionMock->getIdentifier()->willReturn("test"); $requestMock = $this->prophesize(DeliveryExecutionDeleteRequest::class); $requestMock->getDeliveryExecution()->willReturn($deliveryExecutionMock); $result = $this->classUnderTest->deleteDeliveryExecutionData($requestMock->reveal()); $this->assertTrue(is_integer($result)); $this->assertTrue($result === 0); } public function testDeleteDeliveryExecutionDataWithNonEmptyDatabase() { $this->insertNewRow(); $deliveryExecutionMock = $this->prophesize(DeliveryExecution::class); $deliveryExecutionMock->getIdentifier()->willReturn("test"); $requestMock = $this->prophesize(DeliveryExecutionDeleteRequest::class); $requestMock->getDeliveryExecution()->willReturn($deliveryExecutionMock); $result = $this->classUnderTest->deleteDeliveryExecutionData($requestMock->reveal()); $this->assertTrue(is_integer($result)); $this->assertTrue($result === 1); } public function testGetExecutionsByDeliveryWithEmptyDatabase() { $resource = $this->createResource(); $executions = $this->classUnderTest->getExecutionsByDelivery($resource); $this->assertIsArray($executions); $this->assertCount(0, $executions); } public function testGetExecutionsByDeliveryWithNonEmptyDatabase() { $this->insertNewRow(); $resourceMock = $this->prophesize(core_kernel_classes_Resource::class); $resourceMock->getUri()->willReturn("test"); $this->assertTrue(is_array($this->classUnderTest->getExecutionsByDelivery($resourceMock->reveal()))); $this->assertTrue(count($this->classUnderTest->getExecutionsByDelivery($resourceMock->reveal())) === 1); } public function testGetUserExecutions() { $resource = $this->createResource(); $this->assertIsArray($this->classUnderTest->getUserExecutions($resource, "test")); $this->assertCount(0, $this->classUnderTest->getExecutionsByDelivery($resource)); } public function testGetUserExecutionsWithNonEmptyDatabase() { $this->insertNewRow(); $resourceMock = $this->prophesize(core_kernel_classes_Resource::class); $resourceMock->getUri()->willReturn("test"); $this->assertTrue(is_array($this->classUnderTest->getUserExecutions($resourceMock->reveal(), "test"))); $this->assertTrue(count($this->classUnderTest->getUserExecutions($resourceMock->reveal(), "test")) === 1); } public function testGetDeliveryExecutionsByStatus() { $this->assertTrue(is_array($this->classUnderTest->getDeliveryExecutionsByStatus("test", "test"))); $this->assertTrue(count($this->classUnderTest->getDeliveryExecutionsByStatus("test", "test")) === 0); } public function testGetDeliveryExecutionsByStatusWithNonEmptyDatabase() { $this->insertNewRow(); $this->assertTrue(is_array($this->classUnderTest->getDeliveryExecutionsByStatus("test", "test"))); $this->assertTrue(count($this->classUnderTest->getDeliveryExecutionsByStatus("test", "test")) === 1); } public function testSpawnDeliveryExecution() { $this->assertInstanceOf(DeliveryExecution::class, $this->classUnderTest->spawnDeliveryExecution("test", "test", "test", "test")); } public function testInitDeliveryExecution() { $resourceMock = $this->prophesize(core_kernel_classes_Resource::class); $resourceMock->getLabel()->willReturn("test"); $resourceMock->getUri()->willReturn("test"); $this->assertInstanceOf(DeliveryExecution::class, $this->classUnderTest->initDeliveryExecution($resourceMock->reveal(), "test")); } public function testGetDeliveryExecution() { $this->assertInstanceOf(DeliveryExecution::class, $this->classUnderTest->getDeliveryExecution("test")); } public function testGetPersistence() { $this->assertInstanceOf(\common_persistence_SqlPersistence::class, $this->classUnderTest->getPersistence()); } private function insertNewRow() { $query = "INSERT INTO " . RdsDeliveryExecutionService::TABLE_NAME . " (" . RdsDeliveryExecutionService::COLUMN_ID . ", " . RdsDeliveryExecutionService::COLUMN_DELIVERY_ID . ", " . RdsDeliveryExecutionService::COLUMN_USER_ID . ", " . RdsDeliveryExecutionService::COLUMN_STATUS . ", " . RdsDeliveryExecutionService::COLUMN_FINISHED_AT . ", " . RdsDeliveryExecutionService::COLUMN_STARTED_AT . ", " . RdsDeliveryExecutionService::COLUMN_LABEL . ") VALUES (" . "'test', 'test', 'test', 'test', '', '" . $this->persistence->getPlatform()->getNowExpression() . "', 'test'" . ")" ; $this->persistence->exec($query); } private function createResource(): core_kernel_classes_Resource { /** @var core_kernel_classes_Resource|ObjectProphecy $resourceMock */ $resourceMock = $this->prophesize(core_kernel_classes_Resource::class); $resourceMock->getUri()->willReturn('http://tao.lu/test#1'); return $resourceMock->reveal(); } }