Author: Dariusz Rumiński (dariusz.ruminski@gmail.com)
 public function testPrepareCommandOnHhvm()
 {
     if (!defined('HHVM_VERSION')) {
         $this->markTestSkipped('Skip tests for HHVM compiler when running on PHP compiler.');
     }
     $this->assertSame($this->fixEscape('"hhvm" --php -l "foo.php"'), AccessibleObject::create(new Linter('hhvm'))->prepareCommand('foo.php'));
 }
 /**
  * @covers PhpCsFixer\FixerFactory::attachConfig
  */
 public function testMethodAttachConfig()
 {
     $factory = new FixerFactory();
     $fixer = new Psr0Fixer();
     $factory->registerFixer($fixer);
     $mock = $this->getMock('PhpCsFixer\\ConfigInterface');
     $testInstance = $factory->attachConfig($mock);
     $property = AccessibleObject::create($fixer)->config;
     $this->assertSame($mock, $property);
 }
示例#3
0
 public function provideCustomTokenPrefixCases()
 {
     $transformers = Transformers::create();
     $items = AccessibleObject::create($transformers)->items;
     $cases = array();
     foreach ($items as $item) {
         foreach ($item->getCustomTokenNames() as $name) {
             $cases[] = array($name);
         }
     }
     return $cases;
 }
 public function provideTestFixCases()
 {
     $methodsMap = AccessibleObject::create($this->getFixer())->assertionMap;
     $cases = array(array('<?php $self->foo();'));
     foreach ($methodsMap as $methodBefore => $methodAfter) {
         $cases[] = array("<?php \$sth->{$methodBefore}(1, 1);");
         $cases[] = array("<?php \$sth->{$methodAfter}(1, 1);");
         $cases[] = array("<?php \$this->{$methodAfter}(1, 2);", "<?php \$this->{$methodBefore}(1, 2);");
         $cases[] = array("<?php \$this->{$methodAfter}(1, 2); \$this->{$methodAfter}(1, 2);", "<?php \$this->{$methodBefore}(1, 2); \$this->{$methodBefore}(1, 2);");
         $cases[] = array("<?php \$this->{$methodAfter}(1, 2, 'descr');", "<?php \$this->{$methodBefore}(1, 2, 'descr');");
         $cases[] = array("<?php \$this->/*aaa*/{$methodAfter} \t /**bbb*/  ( /*ccc*/1  , 2);", "<?php \$this->/*aaa*/{$methodBefore} \t /**bbb*/  ( /*ccc*/1  , 2);");
         $cases[] = array("<?php \$this->{$methodAfter}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');", "<?php \$this->{$methodBefore}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');");
     }
     return $cases;
 }
 public function testCwd()
 {
     $this->resolver->setCwd('foo');
     $property = AccessibleObject::create($this->resolver)->cwd;
     $this->assertSame('foo', $property);
 }
示例#6
0
 /**
  * @dataProvider provideCalculateExitStatusCases
  */
 public function testCalculateExitStatus($expected, $isDryRun, $hasChangedFiles, $hasInvalidErrors, $hasExceptionErrors)
 {
     $command = new AccessibleObject(new FixCommand());
     $this->assertSame($expected, $command->calculateExitStatus($isDryRun, $hasChangedFiles, $hasInvalidErrors, $hasExceptionErrors));
 }
 private function assertTokens(Tokens $expectedTokens, Tokens $inputTokens)
 {
     foreach ($expectedTokens as $index => $expectedToken) {
         $inputToken = $inputTokens[$index];
         $this->assertTrue($expectedToken->equals($inputToken), sprintf('The token at index %d must be %s, got %s', $index, $expectedToken->toJson(), $inputToken->toJson()));
     }
     $this->assertSame($expectedTokens->count(), $inputTokens->count(), 'The collection must have the same length than the expected one.');
     $foundTokenKinds = array_keys(AccessibleObject::create($expectedTokens)->foundTokenKinds);
     foreach ($foundTokenKinds as $tokenKind) {
         $this->assertTrue($inputTokens->isTokenKindFound($tokenKind), sprintf('The token kind %s must be found in fixed tokens collection.', $tokenKind));
     }
 }
 public function testCreate()
 {
     $object = AccessibleObject::create(new \stdClass());
     $this->assertInstanceOf('PhpCsFixer\\Test\\AccessibleObject', $object);
 }
 /**
  * @dataProvider provideCases
  */
 public function testCountArguments($code, $openIndex, $closeIndex, $argumentsCount)
 {
     $mock = new AccessibleObject($this->getMockForAbstractClass('\\PhpCsFixer\\AbstractFunctionReferenceFixer'));
     $this->assertSame($argumentsCount, $mock->countArguments(Tokens::fromCode($code), $openIndex, $closeIndex));
 }