From 6dfd5d507d9863f987b30b0a5ab4268aea2ed875 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Thu, 2 Aug 2012 11:09:40 +0000 Subject: J'étais parti sur un download pourri de Cake. Les gars on abusé sur GitHub. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2012-php-weave/trunk@7 d972a294-176a-4cf9-8ea1-fcd5b0c30f5c --- .../lib/Cake/TestSuite/CakeTestCase.php | 679 +++++++++++++++++++++ .../lib/Cake/TestSuite/CakeTestLoader.php | 123 ++++ .../lib/Cake/TestSuite/CakeTestRunner.php | 103 ++++ .../lib/Cake/TestSuite/CakeTestSuite.php | 63 ++ .../lib/Cake/TestSuite/CakeTestSuiteCommand.php | 171 ++++++ .../lib/Cake/TestSuite/CakeTestSuiteDispatcher.php | 276 +++++++++ .../lib/Cake/TestSuite/ControllerTestCase.php | 378 ++++++++++++ .../Cake/TestSuite/Coverage/BaseCoverageReport.php | 179 ++++++ .../Cake/TestSuite/Coverage/HtmlCoverageReport.php | 201 ++++++ .../Cake/TestSuite/Coverage/TextCoverageReport.php | 63 ++ .../Cake/TestSuite/Fixture/CakeFixtureManager.php | 282 +++++++++ .../lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 269 ++++++++ .../lib/Cake/TestSuite/Fixture/CakeTestModel.php | 70 +++ .../Cake/TestSuite/Reporter/CakeBaseReporter.php | 210 +++++++ .../Cake/TestSuite/Reporter/CakeHtmlReporter.php | 377 ++++++++++++ .../Cake/TestSuite/Reporter/CakeTextReporter.php | 187 ++++++ .../lib/Cake/TestSuite/templates/footer.php | 36 ++ .../lib/Cake/TestSuite/templates/header.php | 146 +++++ .../lib/Cake/TestSuite/templates/menu.php | 51 ++ .../TestSuite/templates/missing_connection.php | 27 + .../lib/Cake/TestSuite/templates/phpunit.php | 36 ++ .../lib/Cake/TestSuite/templates/xdebug.php | 28 + 22 files changed, 3955 insertions(+) create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestCase.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestLoader.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestRunner.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuite.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteCommand.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/ControllerTestCase.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/TextCoverageReport.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestFixture.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestModel.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeTextReporter.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/footer.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/header.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/menu.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/missing_connection.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/phpunit.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/templates/xdebug.php (limited to 'poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite') diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestCase.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestCase.php new file mode 100644 index 0000000..3509243 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestCase.php @@ -0,0 +1,679 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.TestSuite + * @since CakePHP(tm) v 1.2.0.4667 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::uses('CakeFixtureManager', 'TestSuite/Fixture'); +App::uses('CakeTestFixture', 'TestSuite/Fixture'); + +/** + * CakeTestCase class + * + * @package Cake.TestSuite + */ +abstract class CakeTestCase extends PHPUnit_Framework_TestCase { + +/** + * The class responsible for managing the creation, loading and removing of fixtures + * + * @var CakeFixtureManager + */ + public $fixtureManager = null; + +/** + * By default, all fixtures attached to this class will be truncated and reloaded after each test. + * Set this to false to handle manually + * + * @var array + */ + public $autoFixtures = true; + +/** + * Set this to false to avoid tables to be dropped if they already exist + * + * @var boolean + */ + public $dropTables = true; + +/** + * Configure values to restore at end of test. + * + * @var array + */ + protected $_configure = array(); + +/** + * Path settings to restore at the end of the test. + * + * @var array + */ + protected $_pathRestore = array(); + +/** + * Runs the test case and collects the results in a TestResult object. + * If no TestResult object is passed a new one will be created. + * This method is run for each test method in this class + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + */ + public function run(PHPUnit_Framework_TestResult $result = null) { + if (!empty($this->fixtureManager)) { + $this->fixtureManager->load($this); + } + $result = parent::run($result); + if (!empty($this->fixtureManager)) { + $this->fixtureManager->unload($this); + } + return $result; + } + +/** + * Called when a test case method is about to start (to be overridden when needed.) + * + * @param string $method Test method about to get executed. + * @return void + */ + public function startTest($method) { + } + +/** + * Called when a test case method has been executed (to be overridden when needed.) + * + * @param string $method Test method about that was executed. + * @return void + */ + public function endTest($method) { + } + +/** + * Overrides SimpleTestCase::skipIf to provide a boolean return value + * + * @param boolean $shouldSkip + * @param string $message + * @return boolean + */ + public function skipIf($shouldSkip, $message = '') { + if ($shouldSkip) { + $this->markTestSkipped($message); + } + return $shouldSkip; + } + +/** + * Setup the test case, backup the static object values so they can be restored. + * Specifically backs up the contents of Configure and paths in App if they have + * not already been backed up. + * + * @return void + */ + public function setUp() { + parent::setUp(); + + if (empty($this->_configure)) { + $this->_configure = Configure::read(); + } + if (empty($this->_pathRestore)) { + $this->_pathRestore = App::paths(); + } + if (class_exists('Router', false)) { + Router::reload(); + } + } + +/** + * teardown any static object changes and restore them. + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + App::build($this->_pathRestore, App::RESET); + if (class_exists('ClassRegistry', false)) { + ClassRegistry::flush(); + } + if (!empty($this->_configure)) { + Configure::clear(); + Configure::write($this->_configure); + } + if (isset($_GET['debug']) && $_GET['debug']) { + ob_flush(); + } + } + +/** + * See CakeTestSuiteDispatcher::date() + * + * @param string $format format to be used. + * @return string + */ + public static function date($format = 'Y-m-d H:i:s') { + return CakeTestSuiteDispatcher::date($format); + } + +// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP + +/** + * Announces the start of a test. + * + * @param string $method Test method just started. + * @return void + */ + protected function assertPreConditions() { + parent::assertPreConditions(); + $this->startTest($this->getName()); + } + +/** + * Announces the end of a test. + * + * @param string $method Test method just finished. + * @return void + */ + protected function assertPostConditions() { + parent::assertPostConditions(); + $this->endTest($this->getName()); + } + +// @codingStandardsIgnoreEnd + +/** + * Chooses which fixtures to load for a given test + * + * @param string $fixture Each parameter is a model name that corresponds to a + * fixture, i.e. 'Post', 'Author', etc. + * @return void + * @see CakeTestCase::$autoFixtures + * @throws Exception when no fixture manager is available. + */ + public function loadFixtures() { + if (empty($this->fixtureManager)) { + throw new Exception(__d('cake_dev', 'No fixture manager to load the test fixture')); + } + $args = func_get_args(); + foreach ($args as $class) { + $this->fixtureManager->loadSingle($class); + } + } + +/** + * Assert text equality, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $expected The expected value. + * @param string $result The actual value. + * @param message The message to use for failure. + * @return boolean + */ + public function assertTextNotEquals($expected, $result, $message = '') { + $expected = str_replace(array("\r\n", "\r"), "\n", $expected); + $result = str_replace(array("\r\n", "\r"), "\n", $result); + return $this->assertNotEquals($expected, $result, $message); + } + +/** + * Assert text equality, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $expected The expected value. + * @param string $result The actual value. + * @param message The message to use for failure. + * @return boolean + */ + public function assertTextEquals($expected, $result, $message = '') { + $expected = str_replace(array("\r\n", "\r"), "\n", $expected); + $result = str_replace(array("\r\n", "\r"), "\n", $result); + return $this->assertEquals($expected, $result, $message); + } + +/** + * Asserts that a string starts with a given prefix, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $prefix + * @param string $string + * @param string $message + * @return boolean + */ + public function assertTextStartsWith($prefix, $string, $message = '') { + $prefix = str_replace(array("\r\n", "\r"), "\n", $prefix); + $string = str_replace(array("\r\n", "\r"), "\n", $string); + return $this->assertStringStartsWith($prefix, $string, $message); + } + +/** + * Asserts that a string starts not with a given prefix, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $prefix + * @param string $string + * @param string $message + * @return boolean + */ + public function assertTextStartsNotWith($prefix, $string, $message = '') { + $prefix = str_replace(array("\r\n", "\r"), "\n", $prefix); + $string = str_replace(array("\r\n", "\r"), "\n", $string); + return $this->assertStringStartsNotWith($prefix, $string, $message); + } + +/** + * Asserts that a string ends with a given prefix, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $suffix + * @param string $string + * @param string $message + * @return boolean + */ + public function assertTextEndsWith($suffix, $string, $message = '') { + $suffix = str_replace(array("\r\n", "\r"), "\n", $suffix); + $string = str_replace(array("\r\n", "\r"), "\n", $string); + return $this->assertStringEndsWith($suffix, $string, $message); + } + +/** + * Asserts that a string ends not with a given prefix, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $suffix + * @param string $string + * @param string $message + * @return boolean + */ + public function assertTextEndsNotWith($suffix, $string, $message = '') { + $suffix = str_replace(array("\r\n", "\r"), "\n", $suffix); + $string = str_replace(array("\r\n", "\r"), "\n", $string); + return $this->assertStringEndsNotWith($suffix, $string, $message); + } + +/** + * Assert that a string contains another string, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $needle + * @param string $haystack + * @param string $message + * @param boolean $ignoreCase + * @return boolean + */ + public function assertTextContains($needle, $haystack, $message = '', $ignoreCase = false) { + $needle = str_replace(array("\r\n", "\r"), "\n", $needle); + $haystack = str_replace(array("\r\n", "\r"), "\n", $haystack); + return $this->assertContains($needle, $haystack, $message, $ignoreCase); + } + +/** + * Assert that a text doesn't contain another text, ignoring differences in newlines. + * Helpful for doing cross platform tests of blocks of text. + * + * @param string $needle + * @param string $haystack + * @param string $message + * @param boolean $ignoreCase + * @return boolean + */ + public function assertTextNotContains($needle, $haystack, $message = '', $ignoreCase = false) { + $needle = str_replace(array("\r\n", "\r"), "\n", $needle); + $haystack = str_replace(array("\r\n", "\r"), "\n", $haystack); + return $this->assertNotContains($needle, $haystack, $message, $ignoreCase); + } + +/** + * Takes an array $expected and generates a regex from it to match the provided $string. + * Samples for $expected: + * + * Checks for an input tag with a name attribute (contains any non-empty value) and an id + * attribute that contains 'my-input': + * array('input' => array('name', 'id' => 'my-input')) + * + * Checks for two p elements with some text in them: + * array( + * array('p' => true), + * 'textA', + * '/p', + * array('p' => true), + * 'textB', + * '/p' + * ) + * + * You can also specify a pattern expression as part of the attribute values, or the tag + * being defined, if you prepend the value with preg: and enclose it with slashes, like so: + * array( + * array('input' => array('name', 'id' => 'preg:/FieldName\d+/')), + * 'preg:/My\s+field/' + * ) + * + * Important: This function is very forgiving about whitespace and also accepts any + * permutation of attribute order. It will also allow whitespace between specified tags. + * + * @param string $string An HTML/XHTML/XML string + * @param array $expected An array, see above + * @param string $message SimpleTest failure output string + * @return boolean + */ + public function assertTags($string, $expected, $fullDebug = false) { + $regex = array(); + $normalized = array(); + foreach ((array)$expected as $key => $val) { + if (!is_numeric($key)) { + $normalized[] = array($key => $val); + } else { + $normalized[] = $val; + } + } + $i = 0; + foreach ($normalized as $tags) { + if (!is_array($tags)) { + $tags = (string)$tags; + } + $i++; + if (is_string($tags) && $tags{0} == '<') { + $tags = array(substr($tags, 1) => array()); + } elseif (is_string($tags)) { + $tagsTrimmed = preg_replace('/\s+/m', '', $tags); + + if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') { + $prefix = array(null, null); + + if ($match[0] == '*/') { + $prefix = array('Anything, ', '.*?'); + } + $regex[] = array( + sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))), + sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))), + $i, + ); + continue; + } + if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) { + $tags = $matches[1]; + $type = 'Regex matches'; + } else { + $tags = preg_quote($tags, '/'); + $type = 'Text equals'; + } + $regex[] = array( + sprintf('%s "%s"', $type, $tags), + $tags, + $i, + ); + continue; + } + foreach ($tags as $tag => $attributes) { + $regex[] = array( + sprintf('Open %s tag', $tag), + sprintf('[\s]*<%s', preg_quote($tag, '/')), + $i, + ); + if ($attributes === true) { + $attributes = array(); + } + $attrs = array(); + $explanations = array(); + $i = 1; + foreach ($attributes as $attr => $val) { + if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) { + $attrs[] = $matches[1]; + $explanations[] = sprintf('Regex "%s" matches', $matches[1]); + continue; + } else { + $quotes = '["\']'; + if (is_numeric($attr)) { + $attr = $val; + $val = '.+?'; + $explanations[] = sprintf('Attribute "%s" present', $attr); + } elseif (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) { + $quotes = '["\']?'; + $val = $matches[1]; + $explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val); + } else { + $explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val); + $val = preg_quote($val, '/'); + } + $attrs[] = '[\s]+' . preg_quote($attr, '/') . '=' . $quotes . $val . $quotes; + } + $i++; + } + if ($attrs) { + $permutations = $this->_arrayPermute($attrs); + + $permutationTokens = array(); + foreach ($permutations as $permutation) { + $permutationTokens[] = implode('', $permutation); + } + $regex[] = array( + sprintf('%s', implode(', ', $explanations)), + $permutationTokens, + $i, + ); + } + $regex[] = array( + sprintf('End %s tag', $tag), + '[\s]*\/?[\s]*>[\n\r]*', + $i, + ); + } + } + foreach ($regex as $i => $assertation) { + list($description, $expressions, $itemNum) = $assertation; + $matches = false; + foreach ((array)$expressions as $expression) { + if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) { + $matches = true; + $string = substr($string, strlen($match[0])); + break; + } + } + if (!$matches) { + $this->assertTrue(false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description)); + if ($fullDebug) { + debug($string, true); + debug($regex, true); + } + return false; + } + } + + $this->assertTrue(true, '%s'); + return true; + } + +/** + * Generates all permutation of an array $items and returns them in a new array. + * + * @param array $items An array of items + * @return array + */ + protected function _arrayPermute($items, $perms = array()) { + static $permuted; + if (empty($perms)) { + $permuted = array(); + } + + if (empty($items)) { + $permuted[] = $perms; + } else { + $numItems = count($items) - 1; + for ($i = $numItems; $i >= 0; --$i) { + $newItems = $items; + $newPerms = $perms; + list($tmp) = array_splice($newItems, $i, 1); + array_unshift($newPerms, $tmp); + $this->_arrayPermute($newItems, $newPerms); + } + return $permuted; + } + } + +// @codingStandardsIgnoreStart + +/** + * Compatibility wrapper function for assertEquals + * + * + * @param mixed $result + * @param mixed $expected + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertEqual($result, $expected, $message = '') { + return self::assertEquals($expected, $result, $message); + } + +/** + * Compatibility wrapper function for assertNotEquals + * + * @param mixed $result + * @param mixed $expected + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertNotEqual($result, $expected, $message = '') { + return self::assertNotEquals($expected, $result, $message); + } + +/** + * Compatibility wrapper function for assertRegexp + * + * @param mixed $pattern a regular expression + * @param string $string the text to be matched + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertPattern($pattern, $string, $message = '') { + return self::assertRegExp($pattern, $string, $message); + } + +/** + * Compatibility wrapper function for assertEquals + * + * @param mixed $actual + * @param mixed $expected + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertIdentical($actual, $expected, $message = '') { + return self::assertSame($expected, $actual, $message); + } + +/** + * Compatibility wrapper function for assertNotEquals + * + * @param mixed $actual + * @param mixed $expected + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertNotIdentical($actual, $expected, $message = '') { + return self::assertNotSame($expected, $actual, $message); + } + +/** + * Compatibility wrapper function for assertNotRegExp + * + * @param mixed $pattern a regular expression + * @param string $string the text to be matched + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertNoPattern($pattern, $string, $message = '') { + return self::assertNotRegExp($pattern, $string, $message); + } + + protected function assertNoErrors() { + } + +/** + * Compatibility wrapper function for setExpectedException + * + * @param mixed $expected the name of the Exception or error + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected function expectError($expected = false, $message = '') { + if (!$expected) { + $expected = 'Exception'; + } + $this->setExpectedException($expected, $message); + } + +/** + * Compatibility wrapper function for setExpectedException + * + * @param mixed $expected the name of the Exception + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected function expectException($name = 'Exception', $message = '') { + $this->setExpectedException($name, $message); + } + +/** + * Compatibility wrapper function for assertSame + * + * @param mixed $first + * @param mixed $second + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertReference(&$first, &$second, $message = '') { + return self::assertSame($first, $second, $message); + } + +/** + * Compatibility wrapper for assertIsA + * + * @param string $object + * @param string $type + * @param string $message + * @return void + */ + protected static function assertIsA($object, $type, $message = '') { + return self::assertInstanceOf($type, $object, $message); + } + +/** + * Compatibility function to test if value is between an acceptable range + * + * @param mixed $result + * @param mixed $expected + * @param mixed $margin the rage of acceptation + * @param string $message the text to display if the assertion is not correct + * @return void + */ + protected static function assertWithinMargin($result, $expected, $margin, $message = '') { + $upper = $result + $margin; + $lower = $result - $margin; + return self::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message); + } + +/** + * Compatibility function for skipping. + * + * @param boolean $condition Condition to trigger skipping + * @param string $message Message for skip + * @return boolean + */ + protected function skipUnless($condition, $message = '') { + if (!$condition) { + $this->markTestSkipped($message); + } + return $condition; + } + // @codingStandardsIgnoreStop + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestLoader.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestLoader.php new file mode 100644 index 0000000..83a3607 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestLoader.php @@ -0,0 +1,123 @@ +_resolveTestFile($filePath, $params); + return parent::load('', $file); + } + +/** + * Convert path fragments used by Cake's test runner to absolute paths that can be fed to PHPUnit. + * + * @return void + */ + protected function _resolveTestFile($filePath, $params) { + $basePath = $this->_basePath($params) . DS . $filePath; + $ending = 'Test.php'; + return (strpos($basePath, $ending) === (strlen($basePath) - strlen($ending))) ? $basePath : $basePath . $ending; + } + +/** + * Generates the base path to a set of tests based on the parameters. + * + * @param array $params + * @return string The base path. + */ + protected static function _basePath($params) { + $result = null; + if (!empty($params['core'])) { + $result = CORE_TEST_CASES; + } elseif (!empty($params['plugin'])) { + if (!CakePlugin::loaded($params['plugin'])) { + try { + CakePlugin::load($params['plugin']); + $result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case'; + } catch (MissingPluginException $e) { + } + } else { + $result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case'; + } + } elseif (!empty($params['app'])) { + $result = APP_TEST_CASES; + } + return $result; + } + +/** + * Get the list of files for the test listing. + * + * @return void + */ + public static function generateTestList($params) { + $directory = self::_basePath($params); + $fileList = self::_getRecursiveFileList($directory); + + $testCases = array(); + foreach ($fileList as $testCaseFile) { + $case = str_replace($directory . DS, '', $testCaseFile); + $case = str_replace('Test.php', '', $case); + $testCases[$testCaseFile] = $case; + } + sort($testCases); + return $testCases; + } + +/** + * Gets a recursive list of files from a given directory and matches then against + * a given fileTestFunction, like isTestCaseFile() + * + * @param string $directory The directory to scan for files. + * @param mixed $fileTestFunction + */ + protected static function _getRecursiveFileList($directory = '.') { + $fileList = array(); + if (!is_dir($directory)) { + return $fileList; + } + + $files = new RegexIterator( + new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)), + '/.*Test.php$/' + ); + + foreach ($files as $file) { + $fileList[] = $file->getPathname(); + } + return $fileList; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestRunner.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestRunner.php new file mode 100644 index 0000000..e2f39cd --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestRunner.php @@ -0,0 +1,103 @@ +_params = $params; + } + +/** + * Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager + * + * @param PHPUnit_Framework_Test $suite + * @param array $arguments + * @return void + */ + public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) { + if (isset($arguments['printer'])) { + self::$versionStringPrinted = true; + } + + $fixture = $this->_getFixtureManager($arguments); + foreach ($suite->getIterator() as $test) { + if ($test instanceof CakeTestCase) { + $fixture->fixturize($test); + $test->fixtureManager = $fixture; + } + } + + $return = parent::doRun($suite, $arguments); + $fixture->shutdown(); + return $return; + } + +// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP +/** + * Create the test result and splice on our code coverage reports. + * + * @return PHPUnit_Framework_TestResult + */ + protected function createTestResult() { + $result = new PHPUnit_Framework_TestResult; + if (!empty($this->_params['codeCoverage'])) { + if (method_exists($result, 'collectCodeCoverageInformation')) { + $result->collectCodeCoverageInformation(true); + } + if (method_exists($result, 'setCodeCoverage')) { + $result->setCodeCoverage(new PHP_CodeCoverage()); + } + } + return $result; + } +// @codingStandardsIgnoreEnd + +/** + * Get the fixture manager class specified or use the default one. + * + * @return instance of a fixture manager. + * @throws RuntimeException When fixture manager class cannot be loaded. + */ + protected function _getFixtureManager($arguments) { + if (isset($arguments['fixtureManager'])) { + App::uses($arguments['fixtureManager'], 'TestSuite'); + if (class_exists($arguments['fixtureManager'])) { + return new $arguments['fixtureManager']; + } + throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager'])); + } + App::uses('AppFixtureManager', 'TestSuite'); + if (class_exists('AppFixtureManager')) { + return new AppFixtureManager(); + } + return new CakeFixtureManager(); + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuite.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuite.php new file mode 100644 index 0000000..ca478a0 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuite.php @@ -0,0 +1,63 @@ +read(true, true, true); + + foreach ($files as $file) { + if (substr($file, -4) === '.php') { + $this->addTestFile($file); + } + } + } + +/** + * Recursively adds all the files in a directory to the test suite. + * + * @param string $directory The directory subtree to add tests from. + * @return void + */ + public function addTestDirectoryRecursive($directory = '.') { + $Folder = new Folder($directory); + $files = $Folder->tree(null, true, 'files'); + + foreach ($files as $file) { + if (substr($file, -4) === '.php') { + $this->addTestFile($file); + } + } + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteCommand.php new file mode 100644 index 0000000..6d410ec --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteCommand.php @@ -0,0 +1,171 @@ + $loader)); + } + $this->arguments['loader'] = $loader; + $this->arguments['test'] = $params['case']; + $this->arguments['testFile'] = $params; + $this->_params = $params; + + $this->longOptions['fixture='] = 'handleFixture'; + $this->longOptions['output='] = 'handleReporter'; + } + +/** + * Ugly hack to get around PHPUnit having a hard coded classname for the Runner. :( + * + * @param array $argv + * @param boolean $exit + */ + public function run(array $argv, $exit = true) { + $this->handleArguments($argv); + + $runner = $this->getRunner($this->arguments['loader']); + + if (is_object($this->arguments['test']) && + $this->arguments['test'] instanceof PHPUnit_Framework_Test) { + $suite = $this->arguments['test']; + } else { + $suite = $runner->getTest( + $this->arguments['test'], + $this->arguments['testFile'] + ); + } + + if (count($suite) == 0) { + $skeleton = new PHPUnit_Util_Skeleton_Test( + $suite->getName(), + $this->arguments['testFile'] + ); + + $result = $skeleton->generate(true); + + if (!$result['incomplete']) { + eval(str_replace(array(''), '', $result['code'])); + $suite = new PHPUnit_Framework_TestSuite( + $this->arguments['test'] . 'Test' + ); + } + } + + if ($this->arguments['listGroups']) { + PHPUnit_TextUI_TestRunner::printVersionString(); + + print "Available test group(s):\n"; + + $groups = $suite->getGroups(); + sort($groups); + + foreach ($groups as $group) { + print " - $group\n"; + } + + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } + + unset($this->arguments['test']); + unset($this->arguments['testFile']); + + try { + $result = $runner->doRun($suite, $this->arguments); + } catch (PHPUnit_Framework_Exception $e) { + print $e->getMessage() . "\n"; + } + + if ($exit) { + if (isset($result) && $result->wasSuccessful()) { + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } elseif (!isset($result) || $result->errorCount() > 0) { + exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); + } else { + exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); + } + } + } + +/** + * Create a runner for the command. + * + * @param $loader The loader to be used for the test run. + * @return CakeTestRunner + */ + public function getRunner($loader) { + return new CakeTestRunner($loader, $this->_params); + } + +/** + * Handler for customizing the FixtureManager class/ + * + * @param string $class Name of the class that will be the fixture manager + * @return void + */ + public function handleFixture($class) { + $this->arguments['fixtureManager'] = $class; + } + +/** + * Handles output flag used to change printing on webrunner. + * + * @return void + */ + public function handleReporter($reporter) { + $object = null; + + $type = strtolower($reporter); + $reporter = ucwords($reporter); + $coreClass = 'Cake' . $reporter . 'Reporter'; + App::uses($coreClass, 'TestSuite/Reporter'); + + $appClass = $reporter . 'Reporter'; + App::uses($appClass, 'TestSuite/Reporter'); + + if (!class_exists($appClass)) { + $object = new $coreClass(null, $this->_params); + } else { + $object = new $appClass(null, $this->_params); + } + return $this->arguments['printer'] = $object; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php new file mode 100644 index 0000000..20adfbf --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php @@ -0,0 +1,276 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://cakephp.org CakePHP(tm) Project + * @package Cake.TestSuite + * @since CakePHP(tm) v 1.3 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +define('CORE_TEST_CASES', CAKE . 'Test' . DS . 'Case'); +define('APP_TEST_CASES', TESTS . 'Case'); + +App::uses('CakeTestSuiteCommand', 'TestSuite'); + +/** + * CakeTestSuiteDispatcher handles web requests to the test suite and runs the correct action. + * + * @package Cake.TestSuite + */ +class CakeTestSuiteDispatcher { + +/** + * 'Request' parameters + * + * @var array + */ + public $params = array( + 'codeCoverage' => false, + 'case' => null, + 'core' => false, + 'app' => true, + 'plugin' => null, + 'output' => 'html', + 'show' => 'groups', + 'show_passes' => false, + 'filter' => false, + 'fixture' => null + ); + +/** + * Baseurl for the request + * + * @var string + */ + protected $_baseUrl; + +/** + * Base dir of the request. Used for accessing assets. + * + * @var string + */ + protected $_baseDir; + +/** + * boolean to set auto parsing of params. + * + * @var boolean + */ + protected $_paramsParsed = false; + +/** + * reporter instance used for the request + * + * @var CakeBaseReporter + */ + protected static $_Reporter = null; + +/** + * constructor + * + * @return void + */ + public function __construct() { + $this->_baseUrl = $_SERVER['PHP_SELF']; + $dir = rtrim(dirname($this->_baseUrl), '\\'); + $this->_baseDir = ($dir === '/') ? $dir : $dir . '/'; + } + +/** + * Runs the actions required by the URL parameters. + * + * @return void + */ + public function dispatch() { + $this->_checkPHPUnit(); + $this->_parseParams(); + + if ($this->params['case']) { + $value = $this->_runTestCase(); + } else { + $value = $this->_testCaseList(); + } + + $output = ob_get_clean(); + echo $output; + return $value; + } + +/** + * Static method to initialize the test runner, keeps global space clean + * + * @return void + */ + public static function run() { + $dispatcher = new CakeTestSuiteDispatcher(); + $dispatcher->dispatch(); + } + +/** + * Checks that PHPUnit is installed. Will exit if it doesn't + * + * @return void + */ + protected function _checkPHPUnit() { + $found = $this->loadTestFramework(); + if (!$found) { + $baseDir = $this->_baseDir; + include CAKE . 'TestSuite' . DS . 'templates' . DS . 'phpunit.php'; + exit(); + } + } + +/** + * Checks for the existence of the test framework files + * + * @return boolean true if found, false otherwise + */ + public function loadTestFramework() { + foreach (App::path('vendors') as $vendor) { + if (is_dir($vendor . 'PHPUnit')) { + ini_set('include_path', $vendor . PATH_SEPARATOR . ini_get('include_path')); + break; + } + } + + return include 'PHPUnit' . DS . 'Autoload.php'; + } + +/** + * Checks for the xdebug extension required to do code coverage. Displays an error + * if xdebug isn't installed. + * + * @return void + */ + protected function _checkXdebug() { + if (!extension_loaded('xdebug')) { + $baseDir = $this->_baseDir; + include CAKE . 'TestSuite' . DS . 'templates' . DS . 'xdebug.php'; + exit(); + } + } + +/** + * Generates a page containing the a list of test cases that could be run. + * + * @return void + */ + protected function _testCaseList() { + $command = new CakeTestSuiteCommand('', $this->params); + $Reporter = $command->handleReporter($this->params['output']); + $Reporter->paintDocumentStart(); + $Reporter->paintTestMenu(); + $Reporter->testCaseList(); + $Reporter->paintDocumentEnd(); + } + +/** + * Sets the params, calling this will bypass the auto parameter parsing. + * + * @param array $params Array of parameters for the dispatcher + * @return void + */ + public function setParams($params) { + $this->params = $params; + $this->_paramsParsed = true; + } + +/** + * Parse url params into a 'request' + * + * @return void + */ + protected function _parseParams() { + if (!$this->_paramsParsed) { + if (!isset($_SERVER['SERVER_NAME'])) { + $_SERVER['SERVER_NAME'] = ''; + } + foreach ($this->params as $key => $value) { + if (isset($_GET[$key])) { + $this->params[$key] = $_GET[$key]; + } + } + if (isset($_GET['code_coverage'])) { + $this->params['codeCoverage'] = true; + $this->_checkXdebug(); + } + } + if (empty($this->params['plugin']) && empty($this->params['core'])) { + $this->params['app'] = true; + } + $this->params['baseUrl'] = $this->_baseUrl; + $this->params['baseDir'] = $this->_baseDir; + } + +/** + * Runs a test case file. + * + * @return void + */ + protected function _runTestCase() { + $commandArgs = array( + 'case' => $this->params['case'], + 'core' => $this->params['core'], + 'app' => $this->params['app'], + 'plugin' => $this->params['plugin'], + 'codeCoverage' => $this->params['codeCoverage'], + 'showPasses' => !empty($this->params['show_passes']), + 'baseUrl' => $this->_baseUrl, + 'baseDir' => $this->_baseDir, + ); + + $options = array( + '--filter', $this->params['filter'], + '--output', $this->params['output'], + '--fixture', $this->params['fixture'] + ); + restore_error_handler(); + + try { + self::time(); + $command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs); + $result = $command->run($options); + } catch (MissingConnectionException $exception) { + ob_end_clean(); + $baseDir = $this->_baseDir; + include CAKE . 'TestSuite' . DS . 'templates' . DS . 'missing_connection.php'; + exit(); + } + } + +/** + * Sets a static timestamp + * + * @param boolean $reset to set new static timestamp. + * @return integer timestamp + */ + public static function time($reset = false) { + static $now; + if ($reset || !$now) { + $now = time(); + } + return $now; + } + +/** + * Returns formatted date string using static time + * This method is being used as formatter for created, modified and updated fields in Model::save() + * + * @param string $format format to be used. + * @return string formatted date + */ + public static function date($format) { + return date($format, self::time()); + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/ControllerTestCase.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/ControllerTestCase.php new file mode 100644 index 0000000..d6002f0 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/ControllerTestCase.php @@ -0,0 +1,378 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.TestSuite + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +App::uses('Dispatcher', 'Routing'); +App::uses('CakeTestCase', 'TestSuite'); +App::uses('Router', 'Routing'); +App::uses('CakeRequest', 'Network'); +App::uses('CakeResponse', 'Network'); +App::uses('Helper', 'View'); +App::uses('CakeEvent', 'Event'); + +/** + * ControllerTestDispatcher class + * + * @package Cake.TestSuite + */ +class ControllerTestDispatcher extends Dispatcher { + +/** + * The controller to use in the dispatch process + * + * @var Controller + */ + public $testController = null; + +/** + * Use custom routes during tests + * + * @var boolean + */ + public $loadRoutes = true; + +/** + * Returns the test controller + * + * @return Controller + */ + protected function _getController($request, $response) { + if ($this->testController === null) { + $this->testController = parent::_getController($request, $response); + } + $this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers); + $this->testController->setRequest($request); + $this->testController->response = $this->response; + foreach ($this->testController->Components->attached() as $component) { + $object = $this->testController->Components->{$component}; + if (isset($object->response)) { + $object->response = $response; + } + if (isset($object->request)) { + $object->request = $request; + } + } + return $this->testController; + } + +/** + * Loads routes and resets if the test case dictates it should + * + * @return void + */ + protected function _loadRoutes() { + parent::_loadRoutes(); + if (!$this->loadRoutes) { + Router::reload(); + } + } + +} + +/** + * InterceptContentHelper class + * + * @package Cake.TestSuite + */ +class InterceptContentHelper extends Helper { + +/** + * Intercepts and stores the contents of the view before the layout is rendered + * + * @param string $viewFile The view file + */ + public function afterRender($viewFile) { + $this->_View->assign('__view_no_layout__', $this->_View->fetch('content')); + $this->_View->Helpers->unload('InterceptContent'); + } + +} + +/** + * ControllerTestCase class + * + * @package Cake.TestSuite + */ +abstract class ControllerTestCase extends CakeTestCase { + +/** + * The controller to test in testAction + * + * @var Controller + */ + public $controller = null; + +/** + * Automatically mock controllers that aren't mocked + * + * @var boolean + */ + public $autoMock = true; + +/** + * Use custom routes during tests + * + * @var boolean + */ + public $loadRoutes = true; + +/** + * The resulting view vars of the last testAction call + * + * @var array + */ + public $vars = null; + +/** + * The resulting rendered view of the last testAction call + * + * @var string + */ + public $view = null; + +/** + * The resulting rendered layout+view of the last testAction call + * + * @var string + */ + public $contents = null; + +/** + * The returned result of the dispatch (requestAction), if any + * + * @var string + */ + public $result = null; + +/** + * The headers that would have been sent by the action + * + * @var string + */ + public $headers = null; + +/** + * Flag for checking if the controller instance is dirty. + * Once a test has been run on a controller it should be rebuilt + * to clean up properties. + * + * @var boolean + */ + private $__dirtyController = false; + +/** + * Used to enable calling ControllerTestCase::testAction() without the testing + * framework thinking that it's a test case + * + * @param string $name The name of the function + * @param array $arguments Array of arguments + * @return Function + */ + public function __call($name, $arguments) { + if ($name == 'testAction') { + return call_user_func_array(array($this, '_testAction'), $arguments); + } + } + +/** + * Lets you do functional tests of a controller action. + * + * ### Options: + * + * - `data` Will be used as the request data. If the `method` is GET, + * data will be used a GET params. If the `method` is POST, it will be used + * as POST data. By setting `$options['data']` to a string, you can simulate XML or JSON + * payloads to your controllers allowing you to test REST webservices. + * - `method` POST or GET. Defaults to POST. + * - `return` Specify the return type you want. Choose from: + * - `vars` Get the set view variables. + * - `view` Get the rendered view, without a layout. + * - `contents` Get the rendered view including the layout. + * - `result` Get the return value of the controller action. Useful + * for testing requestAction methods. + * + * @param string $url The url to test + * @param array $options See options + */ + protected function _testAction($url = '', $options = array()) { + $this->vars = $this->result = $this->view = $this->contents = $this->headers = null; + + $options = array_merge(array( + 'data' => array(), + 'method' => 'POST', + 'return' => 'result' + ), $options); + + $restore = array('get' => $_GET, 'post' => $_POST); + + $_SERVER['REQUEST_METHOD'] = strtoupper($options['method']); + if (is_array($options['data'])) { + if (strtoupper($options['method']) == 'GET') { + $_GET = $options['data']; + $_POST = array(); + } else { + $_POST = $options['data']; + $_GET = array(); + } + } + $request = $this->getMock('CakeRequest', array('_readInput'), array($url)); + + if (is_string($options['data'])) { + $request->expects($this->any()) + ->method('_readInput') + ->will($this->returnValue($options['data'])); + } + + $Dispatch = new ControllerTestDispatcher(); + foreach (Router::$routes as $route) { + if ($route instanceof RedirectRoute) { + $route->response = $this->getMock('CakeResponse', array('send')); + } + } + $Dispatch->loadRoutes = $this->loadRoutes; + $Dispatch->parseParams(new CakeEvent('ControllerTestCase', $Dispatch, array('request' => $request))); + if (!isset($request->params['controller'])) { + $this->headers = Router::currentRoute()->response->header(); + return; + } + if ($this->__dirtyController) { + $this->controller = null; + } + + $plugin = empty($request->params['plugin']) ? '' : Inflector::camelize($request->params['plugin']) . '.'; + if ($this->controller === null && $this->autoMock) { + $this->generate($plugin . Inflector::camelize($request->params['controller'])); + } + $params = array(); + if ($options['return'] == 'result') { + $params['return'] = 1; + $params['bare'] = 1; + $params['requested'] = 1; + } + $Dispatch->testController = $this->controller; + $Dispatch->response = $this->getMock('CakeResponse', array('send')); + $this->result = $Dispatch->dispatch($request, $Dispatch->response, $params); + $this->controller = $Dispatch->testController; + $this->vars = $this->controller->viewVars; + $this->contents = $this->controller->response->body(); + if (isset($this->controller->View)) { + $this->view = $this->controller->View->fetch('__view_no_layout__'); + } + $this->__dirtyController = true; + $this->headers = $Dispatch->response->header(); + + $_GET = $restore['get']; + $_POST = $restore['post']; + + return $this->{$options['return']}; + } + +/** + * Generates a mocked controller and mocks any classes passed to `$mocks`. By + * default, `_stop()` is stubbed as is sending the response headers, so to not + * interfere with testing. + * + * ### Mocks: + * + * - `methods` Methods to mock on the controller. `_stop()` is mocked by default + * - `models` Models to mock. Models are added to the ClassRegistry so they any + * time they are instantiated the mock will be created. Pass as key value pairs + * with the value being specific methods on the model to mock. If `true` or + * no value is passed, the entire model will be mocked. + * - `components` Components to mock. Components are only mocked on this controller + * and not within each other (i.e., components on components) + * + * @param string $controller Controller name + * @param array $mocks List of classes and methods to mock + * @return Controller Mocked controller + * @throws MissingControllerException When controllers could not be created. + * @throws MissingComponentException When components could not be created. + */ + public function generate($controller, $mocks = array()) { + list($plugin, $controller) = pluginSplit($controller); + if ($plugin) { + App::uses($plugin . 'AppController', $plugin . '.Controller'); + $plugin .= '.'; + } + App::uses($controller . 'Controller', $plugin . 'Controller'); + if (!class_exists($controller . 'Controller')) { + throw new MissingControllerException(array( + 'class' => $controller . 'Controller', + 'plugin' => substr($plugin, 0, -1) + )); + } + ClassRegistry::flush(); + + $mocks = array_merge_recursive(array( + 'methods' => array('_stop'), + 'models' => array(), + 'components' => array() + ), (array)$mocks); + + list($plugin, $name) = pluginSplit($controller); + $_controller = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false); + $_controller->name = $name; + $request = $this->getMock('CakeRequest'); + $response = $this->getMock('CakeResponse', array('_sendHeader')); + $_controller->__construct($request, $response); + + $config = ClassRegistry::config('Model'); + foreach ($mocks['models'] as $model => $methods) { + if (is_string($methods)) { + $model = $methods; + $methods = true; + } + if ($methods === true) { + $methods = array(); + } + ClassRegistry::init($model); + list($plugin, $name) = pluginSplit($model); + $config = array_merge((array)$config, array('name' => $model)); + $_model = $this->getMock($name, $methods, array($config)); + ClassRegistry::removeObject($name); + ClassRegistry::addObject($name, $_model); + } + + foreach ($mocks['components'] as $component => $methods) { + if (is_string($methods)) { + $component = $methods; + $methods = true; + } + if ($methods === true) { + $methods = array(); + } + list($plugin, $name) = pluginSplit($component, true); + $componentClass = $name . 'Component'; + App::uses($componentClass, $plugin . 'Controller/Component'); + if (!class_exists($componentClass)) { + throw new MissingComponentException(array( + 'class' => $componentClass + )); + } + $_component = $this->getMock($componentClass, $methods, array(), '', false); + $_controller->Components->set($name, $_component); + } + + $_controller->constructClasses(); + $this->__dirtyController = false; + + $this->controller = $_controller; + return $this->controller; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php new file mode 100644 index 0000000..0cf23e8 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php @@ -0,0 +1,179 @@ +_rawCoverage = $coverage; + $this->_setParams($reporter); + } + +/** + * Pulls params out of the reporter. + * + * @param CakeBaseReporter $reporter Reporter to suck params out of. + * @return void + */ + protected function _setParams(CakeBaseReporter $reporter) { + if ($reporter->params['app']) { + $this->appTest = true; + } + if ($reporter->params['plugin']) { + $this->pluginTest = Inflector::camelize($reporter->params['plugin']); + } + } + +/** + * Set the coverage data array + * + * @param array $coverage Coverage data to use. + * @return void + */ + public function setCoverage($coverage) { + $this->_rawCoverage = $coverage; + } + +/** + * Gets the base path that the files we are interested in live in. + * + * @return void + */ + public function getPathFilter() { + $path = ROOT . DS; + if ($this->appTest) { + $path .= APP_DIR . DS; + } elseif ($this->pluginTest) { + $path = App::pluginPath($this->pluginTest); + } else { + $path = CAKE; + } + return $path; + } + +/** + * Filters the coverage data by path. Files not in the provided path will be removed. + * + * @param string $path Path to filter files by. + * @return array Array of coverage data for files that match the given path. + */ + public function filterCoverageDataByPath($path) { + $files = array(); + foreach ($this->_rawCoverage as $fileName => $fileCoverage) { + if (strpos($fileName, $path) !== 0) { + continue; + } + $files[$fileName] = $fileCoverage; + } + return $files; + } + +/** + * Calculates how many lines are covered and what the total number of executable lines is. + * + * Handles both PHPUnit3.5 and 3.6 formats. + * + * 3.5 uses -1 for uncovered, and -2 for dead. + * 3.6 uses array() for uncovered and null for dead. + * + * @param array $fileLines + * @param array $coverageData + * @return array. Array of covered, total lines. + */ + protected function _calculateCoveredLines($fileLines, $coverageData) { + $covered = $total = 0; + + //shift line numbers forward one + array_unshift($fileLines, ' '); + unset($fileLines[0]); + + foreach ($fileLines as $lineno => $line) { + if (!isset($coverageData[$lineno])) { + continue; + } + if (is_array($coverageData[$lineno]) && !empty($coverageData[$lineno])) { + $covered++; + $total++; + } elseif ($coverageData[$lineno] === -1 || $coverageData[$lineno] === array()) { + $total++; + } + } + return array($covered, $total); + } + +/** + * Generates report to display. + * + * @return string compiled html report. + */ + abstract public function report(); + +/** + * Generates an coverage 'diff' for $file based on $coverageData. + * + * @param string $filename Name of the file having coverage generated + * @param array $fileLines File data as an array. See file() for how to get one of these. + * @param array $coverageData Array of coverage data to use to generate HTML diffs with + * @return string prepared report for a single file. + */ + abstract public function generateDiff($filename, $fileLines, $coverageData); + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php new file mode 100644 index 0000000..8706888 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php @@ -0,0 +1,201 @@ +getPathFilter(); + $coverageData = $this->filterCoverageDataByPath($pathFilter); + if (empty($coverageData)) { + return '

No files to generate coverage for

'; + } + $output = $this->coverageScript(); + $output .= <<Code coverage results + Toggle all files + +HTML; + foreach ($coverageData as $file => $coverageData) { + $fileData = file($file); + $output .= $this->generateDiff($file, $fileData, $coverageData); + } + return $output; + } + +/** + * Generates an HTML diff for $file based on $coverageData. + * + * Handles both PHPUnit3.5 and 3.6 formats. + * + * 3.5 uses -1 for uncovered, and -2 for dead. + * 3.6 uses array() for uncovered and null for dead. + * + * @param string $filename Name of the file having coverage generated + * @param array $fileLines File data as an array. See file() for how to get one of these. + * @param array $coverageData Array of coverage data to use to generate HTML diffs with + * @return string HTML diff. + */ + public function generateDiff($filename, $fileLines, $coverageData) { + $output = ''; + $diff = array(); + + list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData); + + //shift line numbers forward one; + array_unshift($fileLines, ' '); + unset($fileLines[0]); + + foreach ($fileLines as $lineno => $line) { + $class = 'ignored'; + $coveringTests = array(); + if (!empty($coverageData[$lineno]) && is_array($coverageData[$lineno])) { + $coveringTests = array(); + foreach ($coverageData[$lineno] as $test) { + $class = (is_array($test) && isset($test['id'])) ? $test['id'] : $test; + $testReflection = new ReflectionClass(current(explode('::', $class))); + $this->_testNames[] = $this->_guessSubjectName($testReflection); + $coveringTests[] = $class; + } + $class = 'covered'; + } elseif (isset($coverageData[$lineno]) && ($coverageData[$lineno] === -1 || $coverageData[$lineno] === array())) { + $class = 'uncovered'; + } elseif (array_key_exists($lineno, $coverageData) && ($coverageData[$lineno] === -2 || $coverageData[$lineno] === null)) { + $class .= ' dead'; + } + $diff[] = $this->_paintLine($line, $lineno, $class, $coveringTests); + } + + $percentCovered = 100; + if ($total > 0) { + $percentCovered = round(100 * $covered / $total, 2); + } + $output .= $this->coverageHeader($filename, $percentCovered); + $output .= implode("", $diff); + $output .= $this->coverageFooter(); + return $output; + } + +/** + * Guess the classname the test was for based on the test case filename. + * + * @param ReflectionClass $testReflection. + * @return string Possible test subject name. + */ + protected function _guessSubjectName($testReflection) { + $basename = basename($testReflection->getFilename()); + if (strpos($basename, '.test') !== false) { + list($subject, ) = explode('.', $basename, 2); + return $subject; + } + $subject = str_replace('Test.php', '', $basename); + return $subject; + } + +/** + * Renders the html for a single line in the html diff. + * + * @return void + */ + protected function _paintLine($line, $linenumber, $class, $coveringTests) { + $coveredBy = ''; + if (!empty($coveringTests)) { + $coveredBy = "Covered by:\n"; + foreach ($coveringTests as $test) { + $coveredBy .= $test . "\n"; + } + } + + return sprintf( + '
%s%s
', + $class, + $coveredBy, + $linenumber, + htmlspecialchars($line) + ); + } + +/** + * generate some javascript for the coverage report. + * + * @return void + */ + public function coverageScript() { + return << + function coverage_show_hide(selector) { + var element = document.getElementById(selector); + element.style.display = (element.style.display == 'none') ? '' : 'none'; + } + function coverage_toggle_all() { + var divs = document.querySelectorAll('div.coverage-container'); + var i = divs.length; + while (i--) { + if (divs[i] && divs[i].className.indexOf('primary') == -1) { + divs[i].style.display = (divs[i].style.display == 'none') ? '' : 'none'; + } + } + } + +HTML; + } + +/** + * Generate an HTML snippet for coverage headers + * + * @return void + */ + public function coverageHeader($filename, $percent) { + $filename = basename($filename); + list($file, $ext) = explode('.', $filename); + $display = in_array($file, $this->_testNames) ? 'block' : 'none'; + $primary = $display == 'block' ? 'primary' : ''; + return << +

+ + $filename Code coverage: $percent% + +

+ "; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/TextCoverageReport.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/TextCoverageReport.php new file mode 100644 index 0000000..e258214 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Coverage/TextCoverageReport.php @@ -0,0 +1,63 @@ +getPathFilter(); + $coverageData = $this->filterCoverageDataByPath($pathFilter); + if (empty($coverageData)) { + return 'No files to generate coverage for'; + } + $output = "\nCoverage Report:\n\n"; + foreach ($coverageData as $file => $coverageData) { + $fileData = file($file); + $output .= $this->generateDiff($file, $fileData, $coverageData); + } + return $output; + } + +/** + * Generates a 'diff' report for a file. + * Since diffs are too big for plain text reports a simple file => % covered is done. + * + * @param string $filename Name of the file having coverage generated + * @param array $fileLines File data as an array. See file() for how to get one of these. + * @param array $coverageData Array of coverage data to use to generate HTML diffs with + * @return string + */ + public function generateDiff($filename, $fileLines, $coverageData) { + list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData); + $percentCovered = round(100 * $covered / $total, 2); + return "$filename : $percentCovered%\n"; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php new file mode 100644 index 0000000..d5998ec --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php @@ -0,0 +1,282 @@ +_initialized) { + ClassRegistry::config(array('ds' => 'test', 'testing' => true)); + } + if (empty($test->fixtures) || !empty($this->_processed[get_class($test)])) { + $test->db = $this->_db; + return; + } + $this->_initDb(); + $test->db = $this->_db; + if (!is_array($test->fixtures)) { + $test->fixtures = array_map('trim', explode(',', $test->fixtures)); + } + if (isset($test->fixtures)) { + $this->_loadFixtures($test->fixtures); + } + + $this->_processed[get_class($test)] = true; + } + +/** + * Initializes this class with a DataSource object to use as default for all fixtures + * + * @return void + */ + protected function _initDb() { + if ($this->_initialized) { + return; + } + $db = ConnectionManager::getDataSource('test'); + $db->cacheSources = false; + $this->_db = $db; + $this->_initialized = true; + } + +/** + * Looks for fixture files and instantiates the classes accordingly + * + * @param array $fixtures the fixture names to load using the notation {type}.{name} + * @return void + * @throws UnexpectedValueException when a referenced fixture does not exist. + */ + protected function _loadFixtures($fixtures) { + foreach ($fixtures as $index => $fixture) { + $fixtureFile = null; + $fixtureIndex = $fixture; + if (isset($this->_loaded[$fixture])) { + continue; + } + + if (strpos($fixture, 'core.') === 0) { + $fixture = substr($fixture, strlen('core.')); + $fixturePaths[] = CAKE . 'Test' . DS . 'Fixture'; + } elseif (strpos($fixture, 'app.') === 0) { + $fixture = substr($fixture, strlen('app.')); + $fixturePaths = array( + TESTS . 'Fixture' + ); + } elseif (strpos($fixture, 'plugin.') === 0) { + $parts = explode('.', $fixture, 3); + $pluginName = $parts[1]; + $fixture = $parts[2]; + $fixturePaths = array( + CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture', + TESTS . 'Fixture' + ); + } else { + $fixturePaths = array( + TESTS . 'Fixture', + CAKE . 'Test' . DS . 'Fixture' + ); + } + + $loaded = false; + foreach ($fixturePaths as $path) { + $className = Inflector::camelize($fixture); + if (is_readable($path . DS . $className . 'Fixture.php')) { + $fixtureFile = $path . DS . $className . 'Fixture.php'; + require_once $fixtureFile; + $fixtureClass = $className . 'Fixture'; + $this->_loaded[$fixtureIndex] = new $fixtureClass(); + $this->_fixtureMap[$fixtureClass] = $this->_loaded[$fixtureIndex]; + $loaded = true; + break; + } + } + + if (!$loaded) { + $firstPath = str_replace(array(APP, CAKE_CORE_INCLUDE_PATH, ROOT), '', $fixturePaths[0] . DS . $className . 'Fixture.php'); + throw new UnexpectedValueException(__d('cake_dev', 'Referenced fixture class %s (%s) not found', $className, $firstPath)); + } + } + } + +/** + * Runs the drop and create commands on the fixtures if necessary. + * + * @param CakeTestFixture $fixture the fixture object to create + * @param DataSource $db the datasource instance to use + * @param boolean $drop whether drop the fixture if it is already created or not + * @return void + */ + protected function _setupTable($fixture, $db = null, $drop = true) { + if (!$db) { + if (!empty($fixture->useDbConfig)) { + $db = ConnectionManager::getDataSource($fixture->useDbConfig); + } else { + $db = $this->_db; + } + } + if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) { + return; + } + + $sources = $db->listSources(); + $table = $db->config['prefix'] . $fixture->table; + $exists = in_array($table, $sources); + + if ($drop && $exists) { + $fixture->drop($db); + $fixture->create($db); + } elseif (!$exists) { + $fixture->create($db); + } else { + $fixture->created[] = $db->configKeyName; + } + } + +/** + * Creates the fixtures tables and inserts data on them. + * + * @param CakeTestCase $test the test to inspect for fixture loading + * @return void + */ + public function load(CakeTestCase $test) { + if (empty($test->fixtures)) { + return; + } + $fixtures = $test->fixtures; + if (empty($fixtures) || $test->autoFixtures == false) { + return; + } + + $nested = $test->db->useNestedTransactions; + $test->db->useNestedTransactions = false; + $test->db->begin(); + foreach ($fixtures as $f) { + if (!empty($this->_loaded[$f])) { + $fixture = $this->_loaded[$f]; + $db = ConnectionManager::getDataSource($fixture->useDbConfig); + $this->_setupTable($fixture, $db, $test->dropTables); + $fixture->insert($db); + } + } + $test->db->commit(); + $test->db->useNestedTransactions = $nested; + } + +/** + * Truncates the fixtures tables + * + * @param CakeTestCase $test the test to inspect for fixture unloading + * @return void + */ + public function unload(CakeTestCase $test) { + $fixtures = !empty($test->fixtures) ? $test->fixtures : array(); + foreach (array_reverse($fixtures) as $f) { + if (isset($this->_loaded[$f])) { + $fixture = $this->_loaded[$f]; + if (!empty($fixture->created)) { + foreach ($fixture->created as $ds) { + $db = ConnectionManager::getDataSource($ds); + $fixture->truncate($db); + } + } + } + } + } + +/** + * Creates a single fixture table and loads data into it. + * + * @param string $name of the fixture + * @param DataSource $db DataSource instance or leave null to get DataSource from the fixture + * @return void + * @throws UnexpectedValueException if $name is not a previously loaded class + */ + public function loadSingle($name, $db = null) { + $name .= 'Fixture'; + if (isset($this->_fixtureMap[$name])) { + $fixture = $this->_fixtureMap[$name]; + if (!$db) { + $db = ConnectionManager::getDataSource($fixture->useDbConfig); + } + $this->_setupTable($fixture, $db); + $fixture->truncate($db); + $fixture->insert($db); + } else { + throw new UnexpectedValueException(__d('cake_dev', 'Referenced fixture class %s not found', $name)); + } + } + +/** + * Drop all fixture tables loaded by this class + * + * @return void + */ + public function shutDown() { + foreach ($this->_loaded as $fixture) { + if (!empty($fixture->created)) { + foreach ($fixture->created as $ds) { + $db = ConnectionManager::getDataSource($ds); + $fixture->drop($db); + } + } + } + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestFixture.php new file mode 100644 index 0000000..359d57f --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -0,0 +1,269 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.TestSuite.Fixture + * @since CakePHP(tm) v 1.2.0.4667 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +App::uses('CakeSchema', 'Model'); + +/** + * CakeTestFixture is responsible for building and destroying tables to be used + * during testing. + * + * @package Cake.TestSuite.Fixture + */ +class CakeTestFixture { + +/** + * Name of the object + * + * @var string + */ + public $name = null; + +/** + * Cake's DBO driver (e.g: DboMysql). + * + * @var object + */ + public $db = null; + +/** + * Fixture Datasource + * + * @var string + */ + public $useDbConfig = 'test'; + +/** + * Full Table Name + * + * @var string + */ + public $table = null; + +/** + * List of datasources where this fixture has been created + * + * @var array + */ + public $created = array(); + +/** + * Instantiate the fixture. + * + * @throws CakeException on invalid datasource usage. + */ + public function __construct() { + if ($this->name === null) { + if (preg_match('/^(.*)Fixture$/', get_class($this), $matches)) { + $this->name = $matches[1]; + } else { + $this->name = get_class($this); + } + } + $connection = 'test'; + if (!empty($this->useDbConfig)) { + $connection = $this->useDbConfig; + if (strpos($connection, 'test') !== 0) { + throw new CakeException(__d('cake_dev', 'Invalid datasource %s for object %s', $connection, $this->name)); + } + } + $this->Schema = new CakeSchema(array('name' => 'TestSuite', 'connection' => $connection)); + $this->init(); + } + +/** + * Initialize the fixture. + * + * @return void + * @throws MissingModelException Whe importing from a model that does not exist. + */ + public function init() { + if (isset($this->import) && (is_string($this->import) || is_array($this->import))) { + $import = array_merge( + array('connection' => 'default', 'records' => false), + is_array($this->import) ? $this->import : array('model' => $this->import) + ); + + $this->Schema->connection = $import['connection']; + if (isset($import['model'])) { + list($plugin, $modelClass) = pluginSplit($import['model'], true); + App::uses($modelClass, $plugin . 'Model'); + if (!class_exists($modelClass)) { + throw new MissingModelException(array('class' => $modelClass)); + } + $model = new $modelClass(null, null, $import['connection']); + $db = $model->getDataSource(); + if (empty($model->tablePrefix)) { + $model->tablePrefix = $db->config['prefix']; + } + $this->fields = $model->schema(true); + $this->fields[$model->primaryKey]['key'] = 'primary'; + $this->table = $db->fullTableName($model, false, false); + ClassRegistry::config(array('ds' => 'test')); + ClassRegistry::flush(); + } elseif (isset($import['table'])) { + $model = new Model(null, $import['table'], $import['connection']); + $db = ConnectionManager::getDataSource($import['connection']); + $db->cacheSources = false; + $model->useDbConfig = $import['connection']; + $model->name = Inflector::camelize(Inflector::singularize($import['table'])); + $model->table = $import['table']; + $model->tablePrefix = $db->config['prefix']; + $this->fields = $model->schema(true); + ClassRegistry::flush(); + } + + if (!empty($db->config['prefix']) && strpos($this->table, $db->config['prefix']) === 0) { + $this->table = str_replace($db->config['prefix'], '', $this->table); + } + + if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) { + $this->records = array(); + $query = array( + 'fields' => $db->fields($model, null, array_keys($this->fields)), + 'table' => $db->fullTableName($model), + 'alias' => $model->alias, + 'conditions' => array(), + 'order' => null, + 'limit' => null, + 'group' => null + ); + $records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias); + + if ($records !== false && !empty($records)) { + $this->records = Hash::extract($records, '{n}.' . $model->alias); + } + } + } + + if (!isset($this->table)) { + $this->table = Inflector::underscore(Inflector::pluralize($this->name)); + } + + if (!isset($this->primaryKey) && isset($this->fields['id'])) { + $this->primaryKey = 'id'; + } + } + +/** + * Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully. + * + * @param object $db An instance of the database object used to create the fixture table + * @return boolean True on success, false on failure + */ + public function create($db) { + if (!isset($this->fields) || empty($this->fields)) { + return false; + } + + if (empty($this->fields['tableParameters']['engine'])) { + $canUseMemory = true; + foreach ($this->fields as $field => $args) { + + if (is_string($args)) { + $type = $args; + } elseif (!empty($args['type'])) { + $type = $args['type']; + } else { + continue; + } + + if (in_array($type, array('blob', 'text', 'binary'))) { + $canUseMemory = false; + break; + } + } + + if ($canUseMemory) { + $this->fields['tableParameters']['engine'] = 'MEMORY'; + } + } + $this->Schema->build(array($this->table => $this->fields)); + try { + $db->execute($db->createSchema($this->Schema), array('log' => false)); + $this->created[] = $db->configKeyName; + } catch (Exception $e) { + return false; + } + return true; + } + +/** + * Run after all tests executed, should return SQL statement to drop table for this fixture. + * + * @param object $db An instance of the database object used to create the fixture table + * @return boolean True on success, false on failure + */ + public function drop($db) { + if (empty($this->fields)) { + return false; + } + $this->Schema->build(array($this->table => $this->fields)); + try { + + $db->execute($db->dropSchema($this->Schema), array('log' => false)); + $this->created = array_diff($this->created, array($db->configKeyName)); + } catch (Exception $e) { + return false; + } + return true; + } + +/** + * Run before each tests is executed, should return a set of SQL statements to insert records for the table + * of this fixture could be executed successfully. + * + * @param object $db An instance of the database into which the records will be inserted + * @return boolean on success or if there are no records to insert, or false on failure + */ + public function insert($db) { + if (!isset($this->_insert)) { + $values = array(); + if (isset($this->records) && !empty($this->records)) { + $fields = array(); + foreach ($this->records as $record) { + $fields = array_merge($fields, array_keys(array_intersect_key($record, $this->fields))); + } + $fields = array_unique($fields); + $default = array_fill_keys($fields, null); + foreach ($this->records as $record) { + $fields = array_keys($record); + $values[] = array_values(array_merge($default, $record)); + } + $nested = $db->useNestedTransactions; + $db->useNestedTransactions = false; + $result = $db->insertMulti($this->table, $fields, $values); + $db->useNestedTransactions = $nested; + return $result; + } + return true; + } + } + +/** + * Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after + * truncate. + * + * @param object $db A reference to a db instance + * @return boolean + */ + public function truncate($db) { + $fullDebug = $db->fullDebug; + $db->fullDebug = false; + $return = $db->truncate($this->table); + $db->fullDebug = $fullDebug; + return $return; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestModel.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestModel.php new file mode 100644 index 0000000..22add85 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Fixture/CakeTestModel.php @@ -0,0 +1,70 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.TestSuite.Fixture + * @since CakePHP(tm) v 1.2.0.4667 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +App::uses('Model', 'Model'); + +/** + * A model to extend from to help you during testing. + * + * @package Cake.TestSuite.Fixture + */ +class CakeTestModel extends Model { + + public $useDbConfig = 'test'; + + public $cacheSources = false; + +/** + * Sets default order for the model to avoid failing tests caused by + * incorrect order when no order has been defined in the finds. + * Postgres can return the results in any order it considers appropriate if none is specified + * + * @param array $queryData + * @return array $queryData + */ + public function beforeFind($queryData) { + $pk = $this->primaryKey; + $aliasedPk = $this->alias . '.' . $this->primaryKey; + switch (true) { + case !$pk: + case !$this->useTable: + case !$this->schema('id'): + case !empty($queryData['order'][0]): + case !empty($queryData['group']): + case + (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) || + (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))): + break; + default: + $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC'); + break; + } + return $queryData; + } +/** + * Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields + * + * @param array $data + * @param boolean|array $validate + * @param array $fieldList + */ + + public function save($data = null, $validate = true, $fieldList = array()) { + $db = $this->getDataSource(); + $db->columns['datetime']['formatter'] = 'CakeTestSuiteDispatcher::date'; + return parent::save($data, $validate, $fieldList); + } + +} \ No newline at end of file diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php new file mode 100644 index 0000000..27dfbd7 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php @@ -0,0 +1,210 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://cakephp.org CakePHP(tm) Project + * @since CakePHP(tm) v 1.3 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +require_once 'PHPUnit/TextUI/ResultPrinter.php'; + +/** + * CakeBaseReporter contains common reporting features used in the CakePHP Test suite + * + * @package Cake.TestSuite.Reporter + */ +class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter { + + protected $_headerSent = false; + +/** + * Array of request parameters. Usually parsed GET params. + * + * @var array + */ + public $params = array(); + +/** + * Character set for the output of test reporting. + * + * @var string + */ + protected $_characterSet; + +/** + * Does nothing yet. The first output will + * be sent on the first test start. + * + * ### Params + * + * - show_passes - Should passes be shown + * - plugin - Plugin test being run? + * - core - Core test being run. + * - case - The case being run + * - codeCoverage - Whether the case/group being run is being code covered. + * + * @param string $charset The character set to output with. Defaults to UTF-8 + * @param array $params Array of request parameters the reporter should use. See above. + */ + public function __construct($charset = 'utf-8', $params = array()) { + if (!$charset) { + $charset = 'utf-8'; + } + $this->_characterSet = $charset; + $this->params = $params; + } + +/** + * Retrieves a list of test cases from the active Manager class, + * displaying it in the correct format for the reporter subclass + * + * @return mixed + */ + public function testCaseList() { + $testList = CakeTestLoader::generateTestList($this->params); + return $testList; + } + +/** + * Paints the start of the response from the test suite. + * Used to paint things like head elements in an html page. + * + * @return void + */ + public function paintDocumentStart() { + } + +/** + * Paints the end of the response from the test suite. + * Used to paint things like in an html page. + * + * @return void + */ + public function paintDocumentEnd() { + } + +/** + * Paint a list of test sets, core, app, and plugin test sets + * available. + * + * @return void + */ + public function paintTestMenu() { + } + +/** + * Get the baseUrl if one is available. + * + * @return string The base url for the request. + */ + public function baseUrl() { + if (!empty($_SERVER['PHP_SELF'])) { + return $_SERVER['PHP_SELF']; + } + return ''; + } + + public function printResult(PHPUnit_Framework_TestResult $result) { + $this->paintFooter($result); + } + + public function paintResult(PHPUnit_Framework_TestResult $result) { + $this->paintFooter($result); + } + +/** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { + $this->paintException($e, $test); + } + +/** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { + $this->paintFail($e, $test); + } + +/** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { + $this->paintSkip($e, $test); + } + +/** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { + $this->paintSkip($e, $test); + } + +/** + * A test suite started. + * + * @param PHPUnit_Framework_TestSuite $suite + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { + if (!$this->_headerSent) { + echo $this->paintHeader(); + } + echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n"; + } + +/** + * A test suite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { + } + +/** + * A test started. + * + * @param PHPUnit_Framework_Test $test + */ + public function startTest(PHPUnit_Framework_Test $test) { + } + +/** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + */ + public function endTest(PHPUnit_Framework_Test $test, $time) { + $this->numAssertions += $test->getNumAssertions(); + if ($test->hasFailed()) { + return; + } + $this->paintPass($test, $time); + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php new file mode 100644 index 0000000..5bd2695 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php @@ -0,0 +1,377 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://cakephp.org CakePHP(tm) Project + * @since CakePHP(tm) v 1.2.0.4433 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::uses('CakeBaseReporter', 'TestSuite/Reporter'); + +/** + * CakeHtmlReporter Reports Results of TestSuites and Test Cases + * in an HTML format / context. + * + * @package Cake.TestSuite.Reporter + */ +class CakeHtmlReporter extends CakeBaseReporter { + +/** + * Paints the top of the web page setting the + * title to the name of the starting test. + * + * @return void + */ + public function paintHeader() { + $this->_headerSent = true; + $this->sendContentType(); + $this->sendNoCacheHeaders(); + $this->paintDocumentStart(); + $this->paintTestMenu(); + echo "