Pārlūkot izejas kodu

Updated test documentation

Maurits van der Schee 9 gadus atpakaļ
vecāks
revīzija
c69e65ed48
2 mainītis faili ar 4 papildinājumiem un 106 dzēšanām
  1. 4
    1
      README.md
  2. 0
    105
      test.php

+ 4
- 1
README.md Parādīt failu

@@ -463,7 +463,7 @@ The following types of 404 'Not found' errors may be reported:
463 463
 
464 464
 ## Tests
465 465
 
466
-Yes, written for PHPUnit. Run:
466
+Yes, written for PHPUnit in the file 'tests.php'. You need to configure your test database conenction in this file. After that run:
467 467
 
468 468
 ```
469 469
 $ wget https://phar.phpunit.de/phpunit.phar
@@ -475,8 +475,11 @@ PHPUnit 4.5.0 by Sebastian Bergmann and contributors.
475 475
 Time: 322 ms, Memory: 3.25Mb
476 476
 
477 477
 OK (11 tests, 48 assertions)
478
+$
478 479
 ```
479 480
 
481
+NB: You MUST use an empty database as a desctructive database fixture ('blog.sql') is loaded.
482
+
480 483
 ## License
481 484
 
482 485
 MIT

+ 0
- 105
test.php Parādīt failu

@@ -1,105 +0,0 @@
1
-<?php
2
-require "api.php";
3
-
4
-class MySQL_CRUD_API_Test extends PHPUnit_Framework_TestCase
5
-{
6
-	private function expectQueries($queries)
7
-	{
8
-		$mysqli = $this->getMockBuilder('mysqli')
9
-			->setMethods(array('query','real_escape_string'))
10
-			->getMock();
11
-		$mysqli->expects($this->any())
12
-			->method('real_escape_string')
13
-			->will($this->returnArgument(0));
14
-		$mysqli->expects($this->any())
15
-			->method('query')
16
-			->will($this->returnCallback(function() use ($queries) {
17
-				static $i = 0;
18
-				$args = func_get_args();
19
-				list($query,$fields,$results) = $queries[$i++];
20
-				$fields = array_map(function($v){ return (object)array('name'=>$v); },$fields);
21
-				$this->assertEquals($query,$args[0]);
22
-				$mysqli_result = $this->getMockBuilder('mysqli_result')
23
-					->setMethods(array('fetch_fields','fetch_row','close'))
24
-					->disableOriginalConstructor()
25
-					->getMock();
26
-				$mysqli_result->expects($this->any())
27
-					->method('fetch_fields')
28
-					->willReturn($fields);
29
-				$mysqli_result->expects($this->any())
30
-					->method('fetch_row')
31
-					->will($this->returnCallback(function() use ($results) {
32
-						static $r = 0;
33
-						return isset($results[$r])?$results[$r++]:false;
34
-					}));
35
-				return $mysqli_result;
36
-			}));
37
-
38
-		return $mysqli;
39
-	}
40
-
41
-	private function expect($method,$url,$queries,$output)
42
-	{
43
-		$url = explode('?',$url,2);
44
-		$request = $url[0];
45
-		$get = array();
46
-		if (isset($url[1])) {
47
-			parse_str($url[1],$get);
48
-		}
49
-		$mysqli = $this->expectQueries($queries);
50
-		$config = array(
51
-			'method' =>$method,
52
-			'request' =>$request,
53
-			'get' =>$get,
54
-			'database'=>'database',
55
-			'mysqli'=>$mysqli,
56
-		);
57
-		$api = new MySQL_CRUD_API($config);
58
-		$this->expectOutputString($output);
59
-		$api->executeCommand();
60
-	}
61
-
62
-	public function testList()
63
-	{
64
-		$this->expect(
65
-			"GET",
66
-			"/table",
67
-			array(
68
-				array(
69
-					"SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE 'table' AND `TABLE_SCHEMA` = 'database'",
70
-					array('table_name'),
71
-					array(array('table')),
72
-				),array(
73
-					"SELECT * FROM `table`",
74
-					array('id','name'),
75
-					array(array('1','value1'),array('2','value2'),array('3','value3'),array('4','value4'),array('5','value5')),
76
-				)
77
-			),
78
-			'{"table":{"columns":["id","name"],"records":[["1","value1"],["2","value2"],["3","value3"],["4","value4"],["5","value5"]]}}'
79
-		);
80
-	}
81
-
82
-	public function testListPageFilterMatchOrder()
83
-	{
84
-		$this->expect(
85
-			"GET",
86
-			"/table?page=2,2&filter=id:3&match=from&order=id,desc",
87
-			array(
88
-				array(
89
-					"SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE 'table' AND `TABLE_SCHEMA` = 'database'",
90
-					array('table_name'),
91
-					array(array('table')),
92
-				),array(
93
-					"SELECT COUNT(*) FROM `table` WHERE `id` >= '3'",
94
-					array('count'),
95
-					array(array('3')),
96
-				),array(
97
-					"SELECT * FROM `table` WHERE `id` >= '3' ORDER BY `id` DESC LIMIT 2 OFFSET 2",
98
-					array('id','name'),
99
-					array(array('3','value3')),
100
-				)
101
-			),
102
-			'{"table":{"columns":["id","name"],"records":[["3","value3"]],"results":3}}'
103
-		);
104
-	}
105
-}

Notiek ielāde…
Atcelt
Saglabāt