浏览代码

Adjust namespace
Simplify bootstrap

euromark 11 年之前
父节点
当前提交
10c8d959f2

+ 35 - 5
README.md

@@ -42,19 +42,49 @@ CakePlugin::loadAll(array(
 ```
 
 ## Namespacing
-Using Cake3 and namespaces, don't forget to add "Tools" as namespace to new files.
-Also don't forget the `use` statements. So for a new behavior "Extendable":
+Using Cake3 and namespaces, don't forget to add "Dereuromark\Tools" as namespace to new files.
+Also don't forget the `use` statements.
+
+So for a new behavior "MySlugged" that extends "Slugged" it is:
 ```php
-namespace Tools\Model\Behavior;
+namespace App\Model\Behavior;
 
-use Cake\ORM\Behavior;
+use Dereuromark\Tools\Model\Behavior\SluggedBehavior;
 
-class SluggedBehavior extends Behavior {
+class MySluggedBehavior extends SluggedBehavior {
 }
 ```
 Note that use statements should be in alphabetical order.
 See CakePHP coding standards for details.
 
+### Shortened namespacing
+As long as you don't have a "Tools" namespace already in use and if you want to save
+yourself some namespace typing, you can configure it the way that it does not need the
+the vendor name:
+
+```php
+CakePlugin::load('Tools', array('namespace' => 'Dereuromark\\Tools'));
+```
+
+For `CakePlugin::loadAll()` it's
+
+```php
+CakePlugin::loadAll(array(
+		'Tools' => array('namespace' => 'Dereuromark\\Tools'
+));
+```
+Personally, this is my default configuration for all plugins.
+
+So for a new behavior "MySlugged" that extends "Slugged" it is now:
+```php
+namespace App\Model\Behavior;
+
+use Tools\Model\Behavior\SluggedBehavior;
+
+class MySluggedBehavior extends SluggedBehavior {
+}
+```
+
 ## Testing
 You can test using a local installation of phpunit or the phar version of it:
 

+ 4 - 3
composer.json

@@ -14,15 +14,16 @@
 	],
 	"require":{
 		"php": ">=5.4",
-		"composer/installers": "*"
+		"composer/installers": "*",
+		"cakephp/cakephp": "3.0.*-dev"
 	},
 	"require-dev": {
-		"cakephp/cakephp": "3.0.*-dev",
 		"cakephp/app": "dev-master"
 	},
 	"autoload": {
 		"psr-4": {
-			"Tools\\": "src"
+			"Dereuromark\\Tools\\": "src",
+			"Dereuromark\\Tools\\Test\\": "tests"
 		}
 	},
 	"support":{

+ 1 - 1
src/Console/Command/WhitespaceShell.php

@@ -1,5 +1,5 @@
 <?php
-namespace Tools\Console\Command;
+namespace Dereuromark\Tools\Console\Command;
 
 use Cake\Console\Shell;
 use Cake\Utility\Folder;

+ 1 - 1
src/Model/Behavior/SluggedBehavior.php

@@ -6,7 +6,7 @@
  * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  */
 
-namespace Tools\Model\Behavior;
+namespace Dereuromark\Tools\Model\Behavior;
 
 use Cake\Event\Event;
 use Cake\ORM\Behavior;

+ 1 - 1
src/TestSuite/Traits/ToolsTestTrait.php

@@ -1,5 +1,5 @@
 <?php
-namespace Tools\TestSuite\Traits;
+namespace Dereuromark\Tools\TestSuite\Traits;
 
 use Cake\Controller\Controller;
 use Cake\Network\Response;

+ 1 - 1
tests/Fixture/SluggedArticleFixture.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tools\Test\Fixture;
+namespace Dereuromark\Tools\Test\Fixture;
 
 use Cake\TestSuite\Fixture\TestFixture;
 

+ 3 - 3
tests/TestCase/Console/Command/WhitespaceShellTest.php

@@ -1,7 +1,7 @@
 <?php
-namespace Tools\Test\TestCase\Console\Command;
+namespace Dereuromark\Tools\Test\TestCase\Console\Command;
 
-use Tools\Console\Command\WhitespaceShell;
+use Dereuromark\Tools\Console\Command\WhitespaceShell;
 use Cake\Console\ConsoleIo;
 use Cake\Console\ConsoleOutput;
 use Cake\Console\Shell;
@@ -38,7 +38,7 @@ class WhitespaceShellTest extends TestCase {
 		$io = new ConsoleIo($this->out);
 
 		$this->Shell = $this->getMock(
-			'Tools\Console\Command\WhitespaceShell',
+			'Dereuromark\Tools\Console\Command\WhitespaceShell',
 			['in', 'err', '_stop'],
 			[$io]
 		);

+ 1 - 1
tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tools\Test\TestCase\Model\Behavior;
+namespace Dereuromark\Tools\Test\TestCase\Model\Behavior;
 
 use Cake\Database\Query;
 use Cake\Datasource\ConnectionManager;

+ 9 - 37
tests/bootstrap.php

@@ -1,52 +1,24 @@
 <?php
-function find_root() {
-	$root = dirname(__DIR__);
-	if (is_dir($root . '/vendor/cakephp/cakephp')) {
-		return $root;
-	}
-
-	$root = dirname(dirname(__DIR__));
-	if (is_dir($root . '/vendor/cakephp/cakephp')) {
-		return $root;
-	}
-
-	$root = dirname(dirname(dirname(__DIR__)));
-	if (is_dir($root . '/vendor/cakephp/cakephp')) {
-		return $root;
-	}
-}
-
-function find_app() {
-	if (is_dir(ROOT . '/src')) {
-		return 'src';
-	}
-	return 'App';
-}
-
 define('DS', DIRECTORY_SEPARATOR);
-define('ROOT', find_root());
-define('APP_DIR', find_app());
-define('WEBROOT_DIR', 'webroot');
-define('APP', ROOT . DS . APP_DIR . DS);
-define('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS);
-define('TESTS', ROOT . DS . 'Test' . DS);
+define('ROOT', dirname(__DIR__));
 define('TMP', ROOT . DS . 'tmp' . DS);
 define('LOGS', TMP . 'logs' . DS);
 define('CACHE', TMP . 'cache' . DS);
+define('APP', sys_get_temp_dir());
+define('APP_DIR', 'src');
 define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
 define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
-define('CAKE', CORE_PATH . 'src' . DS);
+define('CAKE', CORE_PATH . APP_DIR . DS);
 
 require ROOT . '/vendor/cakephp/cakephp/src/basics.php';
 require ROOT . '/vendor/autoload.php';
 
 Cake\Core\Configure::write('App', ['namespace' => 'App']);
-Cake\Core\Configure::write('debug', 2);
 
-$TMP = new \Cake\Utility\Folder(TMP);
-$TMP->create(TMP . 'cache/models', 0777);
-$TMP->create(TMP . 'cache/persistent', 0777);
-$TMP->create(TMP . 'cache/views', 0777);
+$Tmp = new \Cake\Utility\Folder(TMP);
+$Tmp->create(TMP . 'cache/models', 0770);
+$Tmp->create(TMP . 'cache/persistent', 0770);
+$Tmp->create(TMP . 'cache/views', 0770);
 
 $cache = [
 	'default' => [
@@ -70,7 +42,7 @@ $cache = [
 
 Cake\Cache\Cache::config($cache);
 
-Cake\Core\Plugin::load('Tools', ['path' => './']);
+Cake\Core\Plugin::load('Tools', ['namespace' => 'Dereuromark\\Tools', 'path' => './']);
 
 // Ensure default test connection is defined
 if (!getenv('db_class')) {