コード例 #1
0
ファイル: PhpTidyTest.php プロジェクト: beckye67/Icing
    /**
     *
     */
    public function testPhpTidyString_formatting()
    {
        // pass in a sting of PHP code to tidy up
        $input = '<?php
		Class Testerizer extends Object {
			/**
			* bad docblock
			* @param string $a
			* @return mixed $output
			*/
			public function func1 ($a = "string")    {
		return $output; ' . '
	}
				public static function func2(){}
			}
		?>';
        $expect = '<?php' . "\n" . 'class Testerizer extends Object {' . "\n" . '	/**' . "\n" . '	 * bad docblock' . "\n" . '	 *' . "\n" . '	 * @param string  $a' . "\n" . '	 * @return mixed $output' . "\n" . '	 */' . "\n" . '	public function func1($a = "string") {' . "\n" . '		return $output;' . "\n" . '	}' . "\n" . '	/**' . "\n" . '	 *' . "\n" . '	 */' . "\n" . '	public static function func2() {}' . "\n" . '}' . "\n" . "?>\n";
        $this->assertEquals($expect, PhpTidy::string($input));
    }
コード例 #2
0
ファイル: FixtureUpdateShell.php プロジェクト: beckye67/Icing
 /**
  * Read in a fixture file and update it
  * - force it to use Icing.AppFastFixture
  * - update the $fields to always match what's on the current database
  * - run Icing.PhpTidy against it
  *
  * @param string $path
  * @return boolean
  */
 public function processFixture($path)
 {
     //Skip fixture update if we don't have a table definaiton, custom dbconfig
     if ($this->getUseTable($path) === false) {
         return true;
     }
     // cleanup the basics
     $appUses = "App::uses('AppFastFixture', 'Icing.Lib');";
     $body = file_get_contents($path);
     // replace old approaches
     $body = preg_replace('#App::[^\\)]*AppFastFixture[^\\)]*\\);#', $appUses, $body);
     // inject App::uses()
     if (strpos($body, $appUses) === false) {
         $body = preg_replace('#(class .* extends )#', $appUses . "\n\$1", $body);
     }
     // replace CakeTestFixture
     $body = str_replace('CakeTestFixture', 'AppFastFixture', $body);
     // remove closing php
     $body = str_replace('?>', '', $body);
     // TODO: replace the $fields array with details from the "current" schema
     try {
         $body = $this->processFixtureFields($path, $body);
     } catch (Exception $e) {
         $this->error('processFixtureFields Exception: ' . $e->getMessage());
     }
     // cleanup up formatting
     App::uses('PhpTidy', 'Icing.Lib');
     $body = PhpTidy::string($body);
     // write out the file
     if (!file_put_contents($path, $body)) {
         $this->error('Unable to write to ' . $path);
     }
     return true;
 }