CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.4 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.4
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeTestCase
  • CakeTestLoader
  • CakeTestRunner
  • CakeTestSuite
  • CakeTestSuiteCommand
  • CakeTestSuiteDispatcher
  • ControllerTestCase
  • ControllerTestDispatcher
  • InterceptContentHelper
  1: <?php
  2: /**
  3:  * TestLoader for CakePHP Test suite.
  4:  *
  5:  * Turns partial paths used on the testsuite console and web UI into full file paths.
  6:  *
  7:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9:  *
 10:  * Licensed under The MIT License
 11:  * For full copyright and license information, please see the LICENSE.txt
 12:  * Redistributions of files must retain the above copyright notice.
 13:  *
 14:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 15:  * @link          http://cakephp.org CakePHP(tm) Project
 16:  * @since         CakePHP(tm) v 2.0
 17:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 18:  * @package Cake.TestSuite
 19:  */
 20: 
 21: /**
 22:  * TestLoader for CakePHP Test suite.
 23:  *
 24:  * Turns partial paths used on the testsuite console and web UI into full file paths.
 25:  *
 26:  * @package Cake.TestSuite
 27:  */
 28: class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
 29: 
 30: /**
 31:  * Load a file and find the first test case / suite in that file.
 32:  *
 33:  * @param string $filePath
 34:  * @param string $params
 35:  * @return ReflectionClass
 36:  */
 37:     public function load($filePath, $params = '') {
 38:         $file = $this->_resolveTestFile($filePath, $params);
 39:         return parent::load('', $file);
 40:     }
 41: 
 42: /**
 43:  * Convert path fragments used by CakePHP's test runner to absolute paths that can be fed to PHPUnit.
 44:  *
 45:  * @param string $filePath
 46:  * @param string $params
 47:  * @return void
 48:  */
 49:     protected function _resolveTestFile($filePath, $params) {
 50:         $basePath = $this->_basePath($params) . DS . $filePath;
 51:         $ending = 'Test.php';
 52:         return (strpos($basePath, $ending) === (strlen($basePath) - strlen($ending))) ? $basePath : $basePath . $ending;
 53:     }
 54: 
 55: /**
 56:  * Generates the base path to a set of tests based on the parameters.
 57:  *
 58:  * @param array $params
 59:  * @return string The base path.
 60:  */
 61:     protected static function _basePath($params) {
 62:         $result = null;
 63:         if (!empty($params['core'])) {
 64:             $result = CORE_TEST_CASES;
 65:         } elseif (!empty($params['plugin'])) {
 66:             if (!CakePlugin::loaded($params['plugin'])) {
 67:                 try {
 68:                     CakePlugin::load($params['plugin']);
 69:                     $result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
 70:                 } catch (MissingPluginException $e) {
 71:                 }
 72:             } else {
 73:                 $result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
 74:             }
 75:         } elseif (!empty($params['app'])) {
 76:             $result = APP_TEST_CASES;
 77:         }
 78:         return $result;
 79:     }
 80: 
 81: /**
 82:  * Get the list of files for the test listing.
 83:  *
 84:  * @param string $params
 85:  * @return array
 86:  */
 87:     public static function generateTestList($params) {
 88:         $directory = self::_basePath($params);
 89:         $fileList = self::_getRecursiveFileList($directory);
 90: 
 91:         $testCases = array();
 92:         foreach ($fileList as $testCaseFile) {
 93:             $case = str_replace($directory . DS, '', $testCaseFile);
 94:             $case = str_replace('Test.php', '', $case);
 95:             $testCases[$testCaseFile] = $case;
 96:         }
 97:         sort($testCases);
 98:         return $testCases;
 99:     }
100: 
101: /**
102:  * Gets a recursive list of files from a given directory and matches then against
103:  * a given fileTestFunction, like isTestCaseFile()
104:  *
105:  * @param string $directory The directory to scan for files.
106:  * @return array
107:  */
108:     protected static function _getRecursiveFileList($directory = '.') {
109:         $fileList = array();
110:         if (!is_dir($directory)) {
111:             return $fileList;
112:         }
113: 
114:         $files = new RegexIterator(
115:             new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)),
116:             '/.*Test.php$/'
117:         );
118: 
119:         foreach ($files as $file) {
120:             $fileList[] = $file->getPathname();
121:         }
122:         return $fileList;
123:     }
124: 
125: }
126: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs