Пример #1
0
 /**
  * Execute the task
  *
  * @return self
  * @throws BuildException
  */
 public function execute()
 {
     if (!$this->getDirectory()) {
         throw new BuildException('Directory is not set');
     }
     $directory = $this->properties->filter($this->getDirectory());
     Pale::run(function () use($directory) {
         return chdir($directory);
     });
     return $this;
 }
Пример #2
0
 /**
  * @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));
 }
Пример #3
0
 /**
  * @covers Pants\Property\Properties::filter
  */
 public function testDetectedPropertyCyclesThrowAnException()
 {
     $this->setExpectedException("\\Pants\\Property\\PropertyNameCycleException");
     $this->properties->one = '${two}';
     $this->properties->two = '${one}';
     $this->properties->filter('${one}');
 }
Пример #4
0
 /**
  * @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);
 }
Пример #5
0
 /**
  * @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));
 }
Пример #6
0
 /**
  * @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();
 }
Пример #7
0
 /**
  * @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();
 }
Пример #8
0
 /**
  * @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();
 }
Пример #9
0
 /**
  * Execute the task
  *
  * @return self
  * @throws BuildException
  */
 public function execute()
 {
     if (!$this->getTarget()) {
         throw new BuildException('No target set');
     }
     $target = $this->properties->filter($this->getTarget());
     $this->targets->{$target}->execute();
     return $this;
 }
Пример #10
0
 /**
  * @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));
 }
Пример #11
0
 /**
  * @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));
 }
Пример #12
0
 /**
  * @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));
 }
Пример #13
0
 /**
  * Execute the task
  *
  * @return self
  * @throws BuildException
  */
 public function execute()
 {
     if (!$this->getFiles()) {
         throw new BuildException("Files are not set");
     }
     if (!$this->getGroup()) {
         throw new BuildException("Group is not set");
     }
     $group = $this->properties->filter($this->getGroup());
     foreach ($this->getFiles() as $file) {
         $file = $this->properties->filter($file);
         Pale::run(function () use($file, $group) {
             return chgrp($file, $group);
         });
     }
     return $this;
 }
Пример #14
0
 /**
  * Execute the task
  *
  * @return self
  * @throws BuildException
  */
 public function execute()
 {
     if (!$this->getFiles()) {
         throw new BuildException("Files are not set");
     }
     if (!$this->getMode()) {
         throw new BuildException("Mode is not set");
     }
     $mode = $this->properties->filter($this->getMode());
     if (is_string($mode)) {
         $mode = octdec($mode);
     }
     foreach ($this->getFiles() as $file) {
         $file = $this->properties->filter($file);
         Pale::run(function () use($file, $mode) {
             return chmod($file, $mode);
         });
     }
     return $this;
 }
Пример #15
0
 /**
  * @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));
 }