public function testSavesFile() { $mockAdapter = $this->getMockBuilder('\\League\\Flysystem\\Adapter\\Local')->disableOriginalConstructor()->setMethods(['has', 'createDir', 'write'])->getMock(); // plugin calls this method 3 times, internally write calls this method each time checking if // the file exist. write has must always return false otherwise it will throw an exception. $mockAdapter->expects($this->exactly(2))->method('has')->will($this->onConsecutiveCalls(false, false)); $mockAdapter->expects($this->once())->method('createDir')->willReturn(true); $mockAdapter->expects($this->once())->method('write')->willReturn(true); $statement = new Class_('some_name'); $event = new GetClassEvent($statement); $event->setFileLocation('/tmp/'); $event->setCode('<?php echo "some code";'); $plugin = new GenerateClassFile($mockAdapter); $plugin->onGetClassGenerateFile($event); }
public function testConstantNameConversion() { $parser = new Parser(new Lexer()); $class = file_get_contents(__DIR__ . '/mock/constants/class_with_constants.php'); $statement = $parser->parse($class); $event = new GetClassEvent($statement[0], '/tmp/'); $event->setCode('<?php echo "some code";'); $event->setUses('use Some\\Namespace;'); $event->setNamespace('namespace Current\\Namespace;'); $plugin = new ConstantNamesToUpper(); $plugin->onSetClassUpdateConstants($event); foreach ($event->getStatements()->stmts as $constant) { $this->assertEquals($constant->consts[0]->value->value, $constant->consts[0]->name); } }
public function testOnGetClassFixClass() { $pathToFile = __DIR__ . '/mock/fixer/original/GetSomeResponse.php'; $pathToFileFixed = __DIR__ . '/mock/fixer/fixed/GetSomeResponse.php'; $code = file_get_contents($pathToFile); $statement = new Class_($code); $event = new GetClassEvent($statement, $pathToFile); $event->setCode($code); $event->setUses('use DateTime;'); $event->setNamespace('namespace SomeNameSpace\\Category;'); $plugin = new PhpCsFixer(); $plugin->onGetClassFixClass($event); $code = file_get_contents($pathToFile); $fixedCode = file_get_contents($pathToFileFixed); $this->assertEquals($fixedCode, $code, 'Files are not equal and they should be.'); }