public function testDoSort() { $input = [3, 1, 2]; $expectedOutput = [1, 2, 3]; $native = $this->getMock(Native::class, ['sort']); $native->expects($this->once())->method('sort')->willReturnCallback(function (&$a) use($input) { $this->assertEquals($input, $a); sort($a); return true; }); $sample = new SampleClass($native); $output = $sample->doSort($input); $this->assertSame($expectedOutput, $output); }
// we will build library in case if it not exist if (! file_exists($sLibraryPath)) { ini_set("phar.readonly", 0); // Could be done in php.ini $oPhar = new Phar($sLibraryPath); // creating new Phar $oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes $oPhar->buildFromDirectory('classes/'); // creating our library using whole directory $oPhar->compress(Phar::GZ); // plus - compressing it into gzip } // when library already compiled - we will using it require_once('phar://'.$sLibraryPath.'.gz'); // demonstration of work $oClass1 = new SampleClass(); echo $oClass1->getAnyContent(); echo '<pre>'; print_r($oClass1); echo '</pre>'; $oClass2 = new SampleClass2(); echo $oClass2->getAnyContent(); echo $oClass2->getContent2(); echo '<pre>'; print_r($oClass2); echo '</pre>'; ?>
/** * Test sum * * @return null */ public function testSum() { $this->assertEquals(5, SampleClass::add(2, 3)); }
/** * We need to cover this method only for tests * * @param string $controller * @param array $params * * @return array */ protected function reDispatch($controller, array $params = []) { $this->sample->doSomething(); $params['action'] = 'index'; return [$controller . 'Controller', $params]; }