Browse Source

PSR-4 comliant tests

Maurits van der Schee 7 years ago
parent
commit
211801a4d3

+ 1
- 1
phpunit.xml View File

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

+ 4
- 3
tests/Api.php View File

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

+ 1
- 0
tests/Config.php.dist View File

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

+ 1
- 0
tests/Config.php.travis View File

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

+ 1
- 2
tests/MysqlTest.php View File

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

+ 1
- 2
tests/PostgresqlTest.php View File

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

+ 1
- 2
tests/SqlServerTest.php View File

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

+ 4
- 5
tests/SqliteTest.php View File

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

+ 2
- 3
tests/TestBase.php View File

1
 <?php
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
     public static function setUpBeforeClass()
6
     public static function setUpBeforeClass()
8
     {
7
     {

+ 1
- 3
tests/Tests.php View File

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

+ 41
- 0
tests/autoload.php View File

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
+});

Loading…
Cancel
Save