ソースを参照

PSR-4 comliant tests

Maurits van der Schee 7年前
コミット
211801a4d3

+ 1
- 1
phpunit.xml ファイルの表示

@@ -1,4 +1,4 @@
1
-<phpunit>
1
+<phpunit bootstrap="tests/autoload.php">
2 2
     <php>
3 3
         <ini name="display_errors" value="true"/>
4 4
     </php>

+ 4
- 3
tests/Api.php ファイルの表示

@@ -1,4 +1,5 @@
1 1
 <?php
2
+namespace PhpCrudApi\Tests;
2 3
 
3 4
 require_once(__DIR__ . '/../api.php');
4 5
 
@@ -12,12 +13,12 @@ class Api
12 13
     protected $config;
13 14
 
14 15
     /**
15
-     * @var PHP_CRUD_API_Test
16
+     * @var PhpCrudApi\Tests\BaseTest
16 17
      */
17 18
     protected $test;
18 19
 
19 20
     /**
20
-     * @var PHP_CRUD_API
21
+     * @var \PHP_CRUD_API
21 22
      */
22 23
     protected $api;
23 24
 
@@ -34,7 +35,7 @@ class Api
34 35
         $query = isset($url['query'])?$url['query']:'';
35 36
         parse_str($query,$get);
36 37
 
37
-        $this->api = new PHP_CRUD_API(array(
38
+        $this->api = new \PHP_CRUD_API(array(
38 39
             'dbengine'=>$this->config['dbengine'],
39 40
             'hostname'=>$this->config['hostname'],
40 41
             'username'=>$this->config['username'],

+ 1
- 0
tests/Config.php.dist ファイルの表示

@@ -1,4 +1,5 @@
1 1
 <?php
2
+namespace PhpCrudApi\Tests;
2 3
 
3 4
 class Config
4 5
 {

+ 1
- 0
tests/Config.php.travis ファイルの表示

@@ -1,4 +1,5 @@
1 1
 <?php
2
+namespace PhpCrudApi\Tests;
2 3
 
3 4
 class Config
4 5
 {

+ 1
- 2
tests/MysqlTest.php ファイルの表示

@@ -1,6 +1,5 @@
1 1
 <?php
2
-
3
-require_once(__DIR__ . '/Tests.php');
2
+namespace PhpCrudApi\Tests;
4 3
 
5 4
 class MysqlTest extends Tests
6 5
 {

+ 1
- 2
tests/PostgresqlTest.php ファイルの表示

@@ -1,6 +1,5 @@
1 1
 <?php
2
-
3
-require_once(__DIR__ . '/Tests.php');
2
+namespace PhpCrudApi\Tests;
4 3
 
5 4
 class PostgresqlTest extends Tests
6 5
 {

+ 1
- 2
tests/SqlServerTest.php ファイルの表示

@@ -1,6 +1,5 @@
1 1
 <?php
2
-
3
-require_once(__DIR__ . '/Tests.php');
2
+namespace PhpCrudApi\Tests;
4 3
 
5 4
 class SqlServerTest extends Tests
6 5
 {

+ 4
- 5
tests/SqliteTest.php ファイルの表示

@@ -1,6 +1,5 @@
1 1
 <?php
2
-
3
-require_once(__DIR__ . '/Tests.php');
2
+namespace PhpCrudApi\Tests;
4 3
 
5 4
 class SqliteTest extends Tests
6 5
 {
@@ -21,10 +20,10 @@ class SqliteTest extends Tests
21 20
      */
22 21
     public function connect($config)
23 22
     {
24
-        $db = new SQLite3($config['database']);
23
+        $db = new \SQLite3($config['database']);
25 24
 
26 25
         if (!$db) {
27
-            die("Could not open '$database' SQLite database: ".SQLite3::lastErrorMsg().' ('.SQLite3::lastErrorCode().")\n");
26
+            die("Could not open '$database' SQLite database: ".\SQLite3::lastErrorMsg().' ('.\SQLite3::lastErrorCode().")\n");
28 27
         }
29 28
 
30 29
         return $db;
@@ -49,7 +48,7 @@ class SqliteTest extends Tests
49 48
     {
50 49
         $major = 3;
51 50
         $minor = 0;
52
-        $version = SQLite3::version();
51
+        $version = \SQLite3::version();
53 52
         $v = explode('.',$version['versionString']);
54 53
         if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
55 54
             die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n");

+ 2
- 3
tests/TestBase.php ファイルの表示

@@ -1,8 +1,7 @@
1 1
 <?php
2
+namespace PhpCrudApi\Tests;
2 3
 
3
-require_once(__DIR__ . '/Config.php');
4
-
5
-abstract class TestBase extends PHPUnit_Framework_TestCase
4
+abstract class TestBase extends \PHPUnit_Framework_TestCase
6 5
 {
7 6
     public static function setUpBeforeClass()
8 7
     {

+ 1
- 3
tests/Tests.php ファイルの表示

@@ -1,7 +1,5 @@
1 1
 <?php
2
-
3
-require_once(__DIR__ . '/TestBase.php');
4
-require_once(__DIR__ . '/Api.php');
2
+namespace PhpCrudApi\Tests;
5 3
 
6 4
 abstract class Tests extends TestBase
7 5
 {

+ 41
- 0
tests/autoload.php ファイルの表示

@@ -0,0 +1,41 @@
1
+<?php
2
+/**
3
+ * An example of a project-specific implementation.
4
+ *
5
+ * After registering this autoload function with SPL, the following line
6
+ * would cause the function to attempt to load the \Foo\Bar\Baz\Qux class
7
+ * from /path/to/project/src/Baz/Qux.php:
8
+ *
9
+ *      new \Foo\Bar\Baz\Qux;
10
+ *
11
+ * @param string $class The fully-qualified class name.
12
+ * @return void
13
+ */
14
+spl_autoload_register(function ($class) {
15
+
16
+    // project-specific namespace prefix
17
+    $prefix = 'PhpCrudApi\\Tests\\';
18
+
19
+    // base directory for the namespace prefix
20
+    $base_dir = __DIR__ . '/';
21
+
22
+    // does the class use the namespace prefix?
23
+    $len = strlen($prefix);
24
+    if (strncmp($prefix, $class, $len) !== 0) {
25
+        // no, move to the next registered autoloader
26
+        return;
27
+    }
28
+
29
+    // get the relative class name
30
+    $relative_class = substr($class, $len);
31
+
32
+    // replace the namespace prefix with the base directory, replace namespace
33
+    // separators with directory separators in the relative class name, append
34
+    // with .php
35
+    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
36
+
37
+    // if the file exists, require it
38
+    if (file_exists($file)) {
39
+        require $file;
40
+    }
41
+});

読み込み中…
キャンセル
保存