assertInstanceOf('FuzeWorks\Async\Task', $dummyTask); } /* ---------------------------------- Basic variables tests --------------------------- */ /** * @depends testClass */ public function testBaseVariables() { // Create dummy task $dummyTask = new Task('testBaseVariables', new EmptyHandler(), true); // test the values $this->assertEquals('testBaseVariables', $dummyTask->getId()); $this->assertInstanceOf(EmptyHandler::class, $dummyTask->getHandler()); $this->assertTrue($dummyTask->getUsePostHandler()); } /** * @depends testBaseVariables */ public function testArguments() { // Create task without arguments $dummyTask1 = new Task('testArguments1', new EmptyHandler(), true); $this->assertEmpty($dummyTask1->getArguments()); // Now create a task with some arguments $dummyTask2 = new Task('testArguments2', new EmptyHandler(), true, 'some', 'arguments'); $this->assertEquals(['some', 'arguments'], $dummyTask2->getArguments()); } /** * @depends testBaseVariables */ public function testPostHandler() { // Create dummy tasks $dummyTask1 = new Task('testPostHandler1', new EmptyHandler(), true); $dummyTask2 = new Task('testPostHandler2', new EmptyHandler(), false); $this->assertTrue($dummyTask1->getUsePostHandler()); $this->assertFalse($dummyTask2->getUsePostHandler()); } /** * @depends testBaseVariables */ public function testConstraints() { // First create a mock constraint $stub = $this->createMock(Constraint::class); // Then add it to the task $dummyTask = new Task('testConstraints', new EmptyHandler(), false); $dummyTask->addConstraint($stub); // Assert it exists $this->assertEquals([$stub], $dummyTask->getConstraints()); } /** * @depends testBaseVariables */ public function testInitHandler() { $mockHandler = $this->createMock(Handler::class); $mockHandler->expects($this->once())->method('init') ->with($this->callback(function($subject){return $subject instanceof Task;})); // Then create a class new Task('testInitHandler', $mockHandler); } /** * @depends testBaseVariables */ public function testStatusCodes() { // Create dummy task $dummyTask = new Task('testStatusCodes', new EmptyHandler(), true); for ($i = 1; $i <= 9; $i++) { $dummyTask->setStatus($i); $this->assertEquals($i, $dummyTask->getStatus()); } } /** * @depends testBaseVariables */ public function testDelayTime() { // Create dummy task $dummyTask = new Task('testDelayTime', new EmptyHandler(), true); $this->assertEquals(0, $dummyTask->getDelayTime()); $dummyTask->setDelayTime(1000); $this->assertEquals(1000, $dummyTask->getDelayTime()); } /** * @depends testBaseVariables */ public function testAttributes() { // Create dummy task $dummyTask = new Task('testAttributes', new EmptyHandler(), true); // First test a non-existing attribute $this->assertNull($dummyTask->attribute('testKey')); // Now add it and test if it is there $dummyTask->addAttribute('testKey', 'SomeContent'); $this->assertEquals('SomeContent', $dummyTask->attribute('testKey')); // Remove attribute $dummyTask->removeAttribute('testKey'); $this->assertNull($dummyTask->attribute('testKey')); // Remove attribute not found $this->expectException(TasksException::class); $dummyTask->removeAttribute('NotExistant'); } /** * @depends testBaseVariables */ public function testOutputsAndErrors() { // Create dummy task $dummyTask = new Task('testOutputsAndErrors', new EmptyHandler(), true); // Check if non are filled $this->assertNull($dummyTask->getOutput()); $this->assertNull($dummyTask->getPostOutput()); $this->assertNull($dummyTask->getErrors()); $this->assertNull($dummyTask->getPostErrors()); // Then write some data to the task $dummyTask->setOutput('SomeOutput', 'SomeErrors'); $dummyTask->setPostOutput('SomePostOutput', 'SomePostErrors'); // And check again $this->assertEquals('SomeOutput', $dummyTask->getOutput()); $this->assertEquals('SomePostOutput', $dummyTask->getPostOutput()); $this->assertEquals('SomeErrors', $dummyTask->getErrors()); $this->assertEquals('SomePostErrors', $dummyTask->getPostErrors()); } /** * @depends testBaseVariables */ public function testRetrySettings() { // Create dummy task $dummyTask = new Task('testRetrySettings', new EmptyHandler(), true); // Test starting position $this->assertEquals([ 'retryOnFail' => false, 'maxRetries' => 2, 'retryPFailures' => true, 'retryRFailures' => true, 'retryPostFailures' => true, 'maxTime' => 30 ], $dummyTask->getSettings()); // Then change the settings $dummyTask->setSettings(true, 30, 60, false, false, false); // And test the new positions $this->assertEquals([ 'retryOnFail' => true, 'maxRetries' => 30, 'retryPFailures' => false, 'retryRFailures' => false, 'retryPostFailures' => false, 'maxTime' => 60 ], $dummyTask->getSettings()); } /** * @depends testBaseVariables */ public function testRetries() { // Create dummy task $dummyTask = new Task('testRetries', new EmptyHandler(), true); // First test the starting position $this->assertEquals(0, $dummyTask->getRetries()); // Then add one and test $dummyTask->addRetry(); $this->assertEquals(1, $dummyTask->getRetries()); // Then reset it and test $dummyTask->resetRetries(); $this->assertEquals(0, $dummyTask->getRetries()); } public function testGetStatusType() { $this->assertEquals('Task::PENDING', Task::getStatusType(Task::PENDING)); $this->assertEquals('Task::RUNNING', Task::getStatusType(Task::RUNNING)); $this->assertEquals('Task::FAILED', Task::getStatusType(Task::FAILED)); $this->assertEquals('Task::PFAILED', Task::getStatusType(Task::PFAILED)); $this->assertEquals('Task::SUCCESS', Task::getStatusType(Task::SUCCESS)); $this->assertEquals('Task::POST', Task::getStatusType(Task::POST)); $this->assertEquals('Task::COMPLETED', Task::getStatusType(Task::COMPLETED)); $this->assertEquals('Task::DELAYED', Task::getStatusType(Task::DELAYED)); $this->assertEquals('Task::CANCELLED', Task::getStatusType(Task::CANCELLED)); $this->assertFalse(Task::getStatusType(10)); } }