/** * JFilesystemPatcher::apply apply the patches * * @param string $udiff Unified diff input string * @param string $root The files root path * @param string $strip The number of '/' to strip * @param array $sources The source files * @param array $destinations The destinations files * @param integer $result The number of files patched * @param mixed $throw The exception throw, false for no exception * * @return void * * @dataProvider JFilesystemPatcherTest::applyData * @since 12.1 */ public function testApply($udiff, $root, $strip, $sources, $destinations, $result, $throw) { if ($throw) { $this->setExpectedException($throw); } foreach ($sources as $path => $content) { file_put_contents($path, $content); } $patcher = JFilesystemPatcher::getInstance()->reset(); $patcher->add($udiff, $root, $strip); $this->assertEquals($result, $patcher->apply(), 'Line:' . __LINE__ . ' The patcher did not patch ' . $result . ' file(s).'); foreach ($destinations as $path => $content) { if (is_null($content)) { $this->assertFalse(is_file($path), 'Line:' . __LINE__ . ' The patcher did not succeed in patching ' . $path); } else { // Remove all vertical characters to ensure system independed compare $content = preg_replace('/\\v/', '', $content); $data = file_get_contents($path); $data = preg_replace('/\\v/', '', $data); $this->assertEquals($content, $data, 'Line:' . __LINE__ . ' The patcher did not succeed in patching ' . $path); } } }
/** * JFilesystemPatcher::apply apply the patches * * @param string $udiff Unified diff input string * @param string $root The files root path * @param string $strip The number of '/' to strip * @param array $sources The source files * @param array $destinations The destinations files * @param integer $result The number of files patched * @param mixed $throw The exception throw, false for no exception * * @return void * * @since 12.1 * * @dataProvider JFilesystemPatcherTest::applyData */ public function testApply($udiff, $root, $strip, $sources, $destinations, $result, $throw) { if ($throw) { $this->setExpectedException($throw); } foreach ($sources as $path => $content) { file_put_contents($path, $content); } $patcher = JFilesystemPatcher::getInstance()->reset(); $patcher->add($udiff, $root, $strip); $this->assertEquals($result, $patcher->apply(), 'Line:' . __LINE__ . ' The patcher did not patch ' . $result . ' file(s).'); foreach ($destinations as $path => $content) { if (is_null($content)) { $this->assertFalse(is_file($path), 'Line:' . __LINE__ . ' The patcher did not succeed in patching ' . $path); } else { $this->assertEquals($content, file_get_contents($path), 'Line:' . __LINE__ . ' The patcher did not succeed in patching ' . $path); } } }