/** * @covers Pants\Task\Chgrp::__construct * @covers Pants\Task\Chgrp::execute */ public function testGroupIsSet() { $this->properties->expects($this->at(0))->method('filter')->with(1000)->will($this->returnArgument(0)); $this->properties->expects($this->at(1))->method('filter')->with($this->file)->will($this->returnArgument(0)); $this->chgrp->setFile($this->file)->setGroup(1000)->execute(); $this->assertEquals(1000, filegroup($this->file)); }
/** * @covers Pants\Task\Chmod::__construct * @covers Pants\Task\Chmod::execute */ public function testPermissionsAsAStringCanBeSet() { $this->properties->expects($this->at(0))->method('filter')->with('654')->will($this->returnArgument(0)); $this->properties->expects($this->at(1))->method('filter')->with($this->file)->will($this->returnArgument(0)); $this->chmod->setFile($this->file)->setMode('654')->execute(); $this->assertTrue((fileperms($this->file) & 0777) === 0654); }
/** * @covers Pants\Task\TokenFilter::__construct * @covers Pants\Task\TokenFilter::execute */ public function testTokensAreReplacedInTheFileOnExecute() { $this->properties->expects($this->at(0))->method('filter')->with('@')->will($this->returnValue('@')); $this->properties->expects($this->at(1))->method('filter')->with($this->file)->will($this->returnValue($this->file)); $this->properties->expects($this->at(2))->method('filter')->with('@')->will($this->returnValue('@')); $this->tokenFilter->setFile($this->file)->addReplacement('asdf', 'fdsa')->addReplacement('qwer', 'rewq')->execute(); $this->assertEquals('fdsa $qwer$', file_get_contents($this->file)); }
/** * @covers Pants\Task\Call::__construct * @covers Pants\Task\Call::execute */ public function testRequestedTargetIsExecuted() { $this->properties->expects($this->once())->method('filter')->with('asdf')->will($this->returnArgument(0)); $target = $this->getMockBuilder('\\Pants\\Target\\Target')->disableOriginalConstructor()->getMock(); $target->expects($this->once())->method('execute')->will($this->returnSelf()); $this->targets->expects($this->once())->method('__get')->with('asdf')->will($this->returnValue($target)); $this->task->setTarget('asdf')->execute(); }
/** * @covers Pants\Target\Target::__construct * @covers Pants\Target\Target::execute */ public function testTasksAreNotExecutedIfUnlessIsSet() { $task = $this->getMock('\\Pants\\Task\\Task'); $task->expects($this->never())->method('execute'); $this->tasks->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator(array($task)))); $this->properties->expects($this->once())->method('__get')->with('one')->will($this->returnValue(true)); $this->target->setUnless(array('one'))->execute(); }
/** * @covers Pants\Task\Execute::__construct * @covers Pants\Task\Execute::execute */ public function testFailedCommandThrowsException() { $this->setExpectedException('Pants\\Task\\Execute\\CommandReturnedErrorException'); $command = 'php failure.php'; $directory = __DIR__ . '/_files'; $this->properties->expects($this->at(0))->method('filter')->with($command)->will($this->returnArgument(0)); $this->properties->expects($this->at(1))->method('filter')->with($directory)->will($this->returnArgument(0)); $this->task->setCommand($command)->setDirectory($directory)->execute(); }
/** * @covers Pants\Task\Copy::__construct * @covers Pants\Task\Copy::execute */ public function testFileIsCopied() { $source = $this->file; $destination = $this->file . '_1'; $this->properties->expects($this->at(0))->method('filter')->with($source)->will($this->returnArgument(0)); $this->properties->expects($this->at(1))->method('filter')->with($destination)->will($this->returnArgument(0)); $this->task->setFile($source)->setDestination($destination)->execute(); $this->assertTrue(file_exists($destination)); $this->assertEquals('testing', file_get_contents($destination)); }
/** * @covers Pants\Task\Touch::__construct * @covers Pants\Task\Touch::execute */ public function testTouchingANonExistentFileCreatesItAndSetsTheModifiedTime() { $file = vfsStream::url('root') . DIRECTORY_SEPARATOR . 'two'; $time = time(); $this->properties->expects($this->at(0))->method('filter')->with($file)->will($this->returnArgument(0)); $this->properties->expects($this->at(1))->method('filter')->with($time)->will($this->returnArgument(0)); $this->touch->setFile($file)->setTime($time)->execute(); $this->assertTrue(file_exists($file)); $this->assertEquals($time, filemtime($file)); }
/** * @covers Pants\Task\Input::__construct * @covers Pants\Task\Input::execute */ public function testValidArgsAreOutput() { $input = fopen('php://memory', 'a+'); fwrite($input, 'one' . PHP_EOL); fseek($input, 0); $output = fopen('php://memory', 'a+'); $this->properties->expects($this->at(0))->method('filter')->with('one')->will($this->returnValue('one')); $this->properties->expects($this->at(1))->method('filter')->with('two')->will($this->returnValue('two')); $this->task->setInputStream($input)->setOutputStream($output)->setPropertyName('test')->setValidArgs(array('one', 'two')); $this->task->execute(); fseek($output, 0); $this->assertContains('[one/two]', stream_get_contents($output)); }
/** * @covers Pants\Task\Delete::__construct * @covers Pants\Task\Delete::execute */ public function testFileIsDeleted() { $this->properties->expects($this->once())->method('filter')->with($this->file)->will($this->returnArgument(0)); $this->task->setFile($this->file)->execute(); $this->assertFalse(file_exists($this->file)); }