/** * @test * @covers ::processDeferred * @uses Foundry\Masonry\Module\FileSystem\Workers\ChangeOwner\Description * @uses Foundry\Masonry\Module\FileSystem\FileSystemTrait * @return void */ public function testProcessDeferredException() { $deferredWrapper = new DeferredWrapper(); // Test Data $target = 'Target file or location'; $owner = 'Who to make the new owner'; $exceptionMessage = 'Something went wrong'; /** @var FileSystem|\PHPUnit_Framework_MockObject_MockObject $fileSystem */ $fileSystem = $this->getMock(FileSystem::class); $fileSystem->expects($this->once())->method('changeOwner')->with($target, $owner)->will($this->throwException(new \Exception($exceptionMessage))); $description = new Description($target, $owner); $task = new Task($description); $worker = $this->getTestSubject(); $worker->setFileSystem($fileSystem); $processDeferred = $this->getObjectMethod($worker, 'processDeferred'); /** @var \Generator $generator */ $generator = $processDeferred($deferredWrapper->getDeferred(), $task); while ($generator->valid()) { $generator->next(); } // Test messages $this->assertSame("", (string) $deferredWrapper->getSuccessOutput()); $this->assertSame("Failed to change the owner of {$target}: {$exceptionMessage}", (string) $deferredWrapper->getFailureOutput()); $this->assertSame("Changing '{$target}' owner to '{$owner}'", (string) $deferredWrapper->getNotificationOutput()); }
/** * @test * @covers ::processDeferred * @uses Foundry\Masonry\Module\FileSystem\Workers\Delete\Description * @uses Foundry\Masonry\Module\FileSystem\FileSystemTrait * @return void */ public function testProcessDeferredSkip() { $deferredWrapper = new DeferredWrapper(); // The rest of test data $testFile = 'schema://root/test'; /** @var FileSystem|\PHPUnit_Framework_MockObject_MockObject $fileSystem */ $fileSystem = $this->getMock(FileSystem::class); $fileSystem->expects($this->once())->method('isFile')->with($testFile)->will($this->returnValue(false)); $fileSystem->expects($this->once())->method('isDirectory')->with($testFile)->will($this->returnValue(false)); $description = new Description($testFile); $task = new Task($description); $worker = $this->getTestSubject(); $worker->setFileSystem($fileSystem); $processDeferred = $this->getObjectMethod($worker, 'processDeferred'); /** @var \Generator $generator */ $generator = $processDeferred($deferredWrapper->getDeferred(), $task); while ($generator->valid()) { $generator->next(); } // Test messages $this->assertSame("File or directory '{$testFile}' does not exist", (string) $deferredWrapper->getSuccessOutput()); $this->assertSame("", (string) $deferredWrapper->getFailureOutput()); $this->assertSame("Deleting file or directory '{$testFile}'", (string) $deferredWrapper->getNotificationOutput()); }
/** * @test * @covers ::processDeferred * @uses Foundry\Masonry\Module\FileSystem\Workers\Copy\Description * @uses Foundry\Masonry\Module\FileSystem\FileSystemTrait * @return void */ public function testProcessDeferredPartialSuccess() { $deferredWrapper = new DeferredWrapper(); // The rest of test data $testFrom = 'schema://root/test'; $testTo = 'schema://root/test-copy'; /** @var FileSystem|\PHPUnit_Framework_MockObject_MockObject $fileSystem */ $fileSystem = $this->getMock(FileSystem::class); $fileSystem->expects($this->once())->method('copy')->with($testFrom, $testTo)->will($this->returnValue(false)); $description = new Description($testFrom, $testTo); $task = new Task($description); $worker = $this->getTestSubject(); $worker->setFileSystem($fileSystem); $processDeferred = $this->getObjectMethod($worker, 'processDeferred'); /** @var \Generator $generator */ $generator = $processDeferred($deferredWrapper->getDeferred(), $task); while ($generator->valid()) { $generator->next(); } // Test messages $this->assertSame("Copied '{$testFrom}' to '{$testTo}'", (string) $deferredWrapper->getSuccessOutput()); $this->assertSame("", (string) $deferredWrapper->getFailureOutput()); $this->assertSame("Directory permissions were not applied correctly", (string) $deferredWrapper->getNotificationOutput()); }
/** * @test * @covers ::processDeferred * @uses Foundry\Masonry\Module\FileSystem\Workers\Template\Description * @uses Foundry\Masonry\Module\FileSystem\FileSystemTrait * @return void */ public function testProcessDeferredException() { $deferredWrapper = new DeferredWrapper(); // Test Data $template = 'Template file'; $target = 'Target file'; $params = ['key-1' => 'value-1']; $input = 'Target file with {{ key-1 }}'; $output = 'Target file with value-1'; $exceptionMessage = 'Exception Message'; /** @var FileSystem|\PHPUnit_Framework_MockObject_MockObject $fileSystem */ $fileSystem = $this->getMock(FileSystem::class); $fileSystem->expects($this->once())->method('getFileContents')->with($template)->will($this->returnValue($input)); $fileSystem->expects($this->once())->method('write')->with($target, $output)->will($this->throwException(new \Exception($exceptionMessage))); $description = new Description($template, $target, $params); $task = new Task($description); $worker = $this->getTestSubject(); $worker->setFileSystem($fileSystem); $processDeferred = $this->getObjectMethod($worker, 'processDeferred'); /** @var \Generator $generator */ $generator = $processDeferred($deferredWrapper->getDeferred(), $task); while ($generator->valid()) { $generator->next(); } // Test messages $this->assertSame("", (string) $deferredWrapper->getSuccessOutput()); $this->assertSame("Could not create '{$target}' from template '{$template}'", (string) $deferredWrapper->getFailureOutput()); $this->assertSame("Could not write template: {$exceptionMessage}", (string) $deferredWrapper->getNotificationOutput()); }
/** * @test * @covers ::processDeferred * @uses Foundry\Masonry\Module\FileSystem\Workers\FileNotExists\Description * @uses Foundry\Masonry\Module\FileSystem\FileSystemTrait * @return void */ public function testProcessDeferredFailure() { $deferredWrapper = new DeferredWrapper(); // Test Data $name = 'Some name'; /** @var FileSystem|\PHPUnit_Framework_MockObject_MockObject $fileSystem */ $fileSystem = $this->getMock(FileSystem::class); $fileSystem->expects($this->once())->method('isFile')->with($name)->will($this->returnValue(true)); $description = new Description($name); $task = new Task($description); $worker = $this->getTestSubject(); $worker->setFileSystem($fileSystem); $processDeferred = $this->getObjectMethod($worker, 'processDeferred'); /** @var \Generator $generator */ $generator = $processDeferred($deferredWrapper->getDeferred(), $task); while ($generator->valid()) { $generator->next(); } // Test messages $this->assertSame("", (string) $deferredWrapper->getSuccessOutput()); $this->assertSame("File '{$name}' exists", (string) $deferredWrapper->getFailureOutput()); $this->assertSame("Checking that file '{$name}' does not exist", (string) $deferredWrapper->getNotificationOutput()); }