Please enable rewrite module on your web server to continue -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gte451f/phalcon-json-api/72bbae0e51cde7b2a746bf1df6dbdbcb8dc027c5/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handle(); 42 | } catch (Phalcon\Exception $e) { 43 | if ($config['application']['debugApp'] == true) { 44 | http_response_code(500); 45 | echo 'Framework exception caught: ' . $e->getMessage(), PHP_EOL; 46 | echo $e->getTraceAsString(), PHP_EOL; 47 | } else { 48 | throw new HTTPException('Framework Exception Caught.', 500, [ 49 | 'dev' => $e->getMessage(), 50 | 'code' => '49846461681613616813.3131' 51 | ]); 52 | } 53 | } catch (PDOException $e) { 54 | // seems like this is only run when an unexpected database exception occurs 55 | if ($config['application']['debugApp'] == true) { 56 | http_response_code(500); 57 | echo 'Database exception caught: ' . $e->getMessage(), PHP_EOL; 58 | echo $e->getTraceAsString(), PHP_EOL; 59 | } else { 60 | throw new DatabaseException('Database Exception Caught.', 500, [ 61 | 'dev' => $e->getMessage(), 62 | 'code' => '546846131616106860' 63 | ]); 64 | } 65 | } -------------------------------------------------------------------------------- /public/test.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/_bootstrap.php: -------------------------------------------------------------------------------- 1 | getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args())); 31 | } 32 | 33 | 34 | /** 35 | * [!] Method is generated. Documentation taken from corresponding module. 36 | * 37 | * Checks that two variables are not equal 38 | * 39 | * @param $expected 40 | * @param $actual 41 | * @param string $message 42 | * @see \Codeception\Module\Asserts::assertNotEquals() 43 | */ 44 | public function assertNotEquals($expected, $actual, $message = null) { 45 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args())); 46 | } 47 | 48 | 49 | /** 50 | * [!] Method is generated. Documentation taken from corresponding module. 51 | * 52 | * Checks that two variables are same 53 | * 54 | * @param $expected 55 | * @param $actual 56 | * @param string $message 57 | * @return mixed|void 58 | * @see \Codeception\Module\Asserts::assertSame() 59 | */ 60 | public function assertSame($expected, $actual, $message = null) { 61 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args())); 62 | } 63 | 64 | 65 | /** 66 | * [!] Method is generated. Documentation taken from corresponding module. 67 | * 68 | * Checks that two variables are not same 69 | * 70 | * @param $expected 71 | * @param $actual 72 | * @param string $message 73 | * @see \Codeception\Module\Asserts::assertNotSame() 74 | */ 75 | public function assertNotSame($expected, $actual, $message = null) { 76 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args())); 77 | } 78 | 79 | 80 | /** 81 | * [!] Method is generated. Documentation taken from corresponding module. 82 | * 83 | * Checks that actual is greater than expected 84 | * 85 | * @param $expected 86 | * @param $actual 87 | * @param string $message 88 | * @see \Codeception\Module\Asserts::assertGreaterThan() 89 | */ 90 | public function assertGreaterThan($expected, $actual, $message = null) { 91 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args())); 92 | } 93 | 94 | 95 | /** 96 | * [!] Method is generated. Documentation taken from corresponding module. 97 | * 98 | * Checks that actual is greater or equal than expected 99 | * 100 | * @param $expected 101 | * @param $actual 102 | * @param string $message 103 | * @see \Codeception\Module\Asserts::assertGreaterThanOrEqual() 104 | */ 105 | public function assertGreaterThanOrEqual($expected, $actual, $message = null) { 106 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args())); 107 | } 108 | 109 | 110 | /** 111 | * [!] Method is generated. Documentation taken from corresponding module. 112 | * 113 | * Checks that actual is less than expected 114 | * 115 | * @param $expected 116 | * @param $actual 117 | * @param string $message 118 | * @see \Codeception\Module\Asserts::assertLessThan() 119 | */ 120 | public function assertLessThan($expected, $actual, $message = null) { 121 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args())); 122 | } 123 | 124 | 125 | /** 126 | * [!] Method is generated. Documentation taken from corresponding module. 127 | * 128 | * Checks that actual is less or equal than expected 129 | * 130 | * @param $expected 131 | * @param $actual 132 | * @param string $message 133 | * @see \Codeception\Module\Asserts::assertLessThanOrEqual() 134 | */ 135 | public function assertLessThanOrEqual($expected, $actual, $message = null) { 136 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args())); 137 | } 138 | 139 | 140 | /** 141 | * [!] Method is generated. Documentation taken from corresponding module. 142 | * 143 | * Checks that haystack contains needle 144 | * 145 | * @param $needle 146 | * @param $haystack 147 | * @param string $message 148 | * @see \Codeception\Module\Asserts::assertContains() 149 | */ 150 | public function assertContains($needle, $haystack, $message = null) { 151 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args())); 152 | } 153 | 154 | 155 | /** 156 | * [!] Method is generated. Documentation taken from corresponding module. 157 | * 158 | * Checks that haystack doesn't contain needle. 159 | * 160 | * @param $needle 161 | * @param $haystack 162 | * @param string $message 163 | * @see \Codeception\Module\Asserts::assertNotContains() 164 | */ 165 | public function assertNotContains($needle, $haystack, $message = null) { 166 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args())); 167 | } 168 | 169 | 170 | /** 171 | * [!] Method is generated. Documentation taken from corresponding module. 172 | * 173 | * Checks that string match with pattern 174 | * 175 | * @param string $pattern 176 | * @param string $string 177 | * @param string $message 178 | * @see \Codeception\Module\Asserts::assertRegExp() 179 | */ 180 | public function assertRegExp($pattern, $string, $message = null) { 181 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args())); 182 | } 183 | 184 | 185 | /** 186 | * [!] Method is generated. Documentation taken from corresponding module. 187 | * 188 | * Checks that string not match with pattern 189 | * 190 | * @param string $pattern 191 | * @param string $string 192 | * @param string $message 193 | * @see \Codeception\Module\Asserts::assertNotRegExp() 194 | */ 195 | public function assertNotRegExp($pattern, $string, $message = null) { 196 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args())); 197 | } 198 | 199 | 200 | /** 201 | * [!] Method is generated. Documentation taken from corresponding module. 202 | * 203 | * Checks that variable is empty. 204 | * 205 | * @param $actual 206 | * @param string $message 207 | * @see \Codeception\Module\Asserts::assertEmpty() 208 | */ 209 | public function assertEmpty($actual, $message = null) { 210 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args())); 211 | } 212 | 213 | 214 | /** 215 | * [!] Method is generated. Documentation taken from corresponding module. 216 | * 217 | * Checks that variable is not empty. 218 | * 219 | * @param $actual 220 | * @param string $message 221 | * @see \Codeception\Module\Asserts::assertNotEmpty() 222 | */ 223 | public function assertNotEmpty($actual, $message = null) { 224 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args())); 225 | } 226 | 227 | 228 | /** 229 | * [!] Method is generated. Documentation taken from corresponding module. 230 | * 231 | * Checks that variable is NULL 232 | * 233 | * @param $actual 234 | * @param string $message 235 | * @see \Codeception\Module\Asserts::assertNull() 236 | */ 237 | public function assertNull($actual, $message = null) { 238 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args())); 239 | } 240 | 241 | 242 | /** 243 | * [!] Method is generated. Documentation taken from corresponding module. 244 | * 245 | * Checks that variable is not NULL 246 | * 247 | * @param $actual 248 | * @param string $message 249 | * @see \Codeception\Module\Asserts::assertNotNull() 250 | */ 251 | public function assertNotNull($actual, $message = null) { 252 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args())); 253 | } 254 | 255 | 256 | /** 257 | * [!] Method is generated. Documentation taken from corresponding module. 258 | * 259 | * Checks that condition is positive. 260 | * 261 | * @param $condition 262 | * @param string $message 263 | * @see \Codeception\Module\Asserts::assertTrue() 264 | */ 265 | public function assertTrue($condition, $message = null) { 266 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args())); 267 | } 268 | 269 | 270 | /** 271 | * [!] Method is generated. Documentation taken from corresponding module. 272 | * 273 | * Checks that condition is negative. 274 | * 275 | * @param $condition 276 | * @param string $message 277 | * @see \Codeception\Module\Asserts::assertFalse() 278 | */ 279 | public function assertFalse($condition, $message = null) { 280 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args())); 281 | } 282 | 283 | 284 | /** 285 | * [!] Method is generated. Documentation taken from corresponding module. 286 | * 287 | * Checks if file exists 288 | * 289 | * @param string $filename 290 | * @param string $message 291 | * @see \Codeception\Module\Asserts::assertFileExists() 292 | */ 293 | public function assertFileExists($filename, $message = null) { 294 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args())); 295 | } 296 | 297 | 298 | /** 299 | * [!] Method is generated. Documentation taken from corresponding module. 300 | * 301 | * Checks if file doesn't exist 302 | * 303 | * @param string $filename 304 | * @param string $message 305 | * @see \Codeception\Module\Asserts::assertFileNotExists() 306 | */ 307 | public function assertFileNotExists($filename, $message = null) { 308 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args())); 309 | } 310 | 311 | 312 | /** 313 | * [!] Method is generated. Documentation taken from corresponding module. 314 | * 315 | * @param $expected 316 | * @param $actual 317 | * @param $description 318 | * @see \Codeception\Module\Asserts::assertGreaterOrEquals() 319 | */ 320 | public function assertGreaterOrEquals($expected, $actual, $description = null) { 321 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args())); 322 | } 323 | 324 | 325 | /** 326 | * [!] Method is generated. Documentation taken from corresponding module. 327 | * 328 | * @param $expected 329 | * @param $actual 330 | * @param $description 331 | * @see \Codeception\Module\Asserts::assertLessOrEquals() 332 | */ 333 | public function assertLessOrEquals($expected, $actual, $description = null) { 334 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args())); 335 | } 336 | 337 | 338 | /** 339 | * [!] Method is generated. Documentation taken from corresponding module. 340 | * 341 | * @param $actual 342 | * @param $description 343 | * @see \Codeception\Module\Asserts::assertIsEmpty() 344 | */ 345 | public function assertIsEmpty($actual, $description = null) { 346 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args())); 347 | } 348 | 349 | 350 | /** 351 | * [!] Method is generated. Documentation taken from corresponding module. 352 | * 353 | * @param $key 354 | * @param $actual 355 | * @param $description 356 | * @see \Codeception\Module\Asserts::assertArrayHasKey() 357 | */ 358 | public function assertArrayHasKey($key, $actual, $description = null) { 359 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args())); 360 | } 361 | 362 | 363 | /** 364 | * [!] Method is generated. Documentation taken from corresponding module. 365 | * 366 | * @param $key 367 | * @param $actual 368 | * @param $description 369 | * @see \Codeception\Module\Asserts::assertArrayNotHasKey() 370 | */ 371 | public function assertArrayNotHasKey($key, $actual, $description = null) { 372 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args())); 373 | } 374 | 375 | 376 | /** 377 | * [!] Method is generated. Documentation taken from corresponding module. 378 | * 379 | * @param $expectedCount 380 | * @param $actual 381 | * @param $description 382 | * @see \Codeception\Module\Asserts::assertCount() 383 | */ 384 | public function assertCount($expectedCount, $actual, $description = null) { 385 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args())); 386 | } 387 | 388 | 389 | /** 390 | * [!] Method is generated. Documentation taken from corresponding module. 391 | * 392 | * @param $class 393 | * @param $actual 394 | * @param $description 395 | * @see \Codeception\Module\Asserts::assertInstanceOf() 396 | */ 397 | public function assertInstanceOf($class, $actual, $description = null) { 398 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args())); 399 | } 400 | 401 | 402 | /** 403 | * [!] Method is generated. Documentation taken from corresponding module. 404 | * 405 | * @param $class 406 | * @param $actual 407 | * @param $description 408 | * @see \Codeception\Module\Asserts::assertNotInstanceOf() 409 | */ 410 | public function assertNotInstanceOf($class, $actual, $description = null) { 411 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args())); 412 | } 413 | 414 | 415 | /** 416 | * [!] Method is generated. Documentation taken from corresponding module. 417 | * 418 | * @param $type 419 | * @param $actual 420 | * @param $description 421 | * @see \Codeception\Module\Asserts::assertInternalType() 422 | */ 423 | public function assertInternalType($type, $actual, $description = null) { 424 | return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args())); 425 | } 426 | 427 | 428 | /** 429 | * [!] Method is generated. Documentation taken from corresponding module. 430 | * 431 | * Fails the test with message. 432 | * 433 | * @param $message 434 | * @see \Codeception\Module\Asserts::fail() 435 | */ 436 | public function fail($message) { 437 | return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); 438 | } 439 | 440 | 441 | /** 442 | * [!] Method is generated. Documentation taken from corresponding module. 443 | * 444 | * Handles and checks exception called inside callback function. 445 | * Either exception class name or exception instance should be provided. 446 | * 447 | * ```php 448 | * expectException(MyException::class, function() { 450 | * $this->doSomethingBad(); 451 | * }); 452 | * 453 | * $I->expectException(new MyException(), function() { 454 | * $this->doSomethingBad(); 455 | * }); 456 | * ``` 457 | * If you want to check message or exception code, you can pass them with exception instance: 458 | * ```php 459 | * expectException(new MyException("Don't do bad things"), function() { 462 | * $this->doSomethingBad(); 463 | * }); 464 | * ``` 465 | * 466 | * @param $exception string or \Exception 467 | * @param $callback 468 | * @see \Codeception\Module\Asserts::expectException() 469 | */ 470 | public function expectException($exception, $callback) { 471 | return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args())); 472 | } 473 | } 474 | -------------------------------------------------------------------------------- /tests/acceptance.suite.yml: -------------------------------------------------------------------------------- 1 | # Codeception Test Suite Configuration 2 | # 3 | # Suite for acceptance tests. 4 | # Perform tests in browser using the WebDriver or PhpBrowser. 5 | # If you need both WebDriver and PHPBrowser tests - create a separate suite. 6 | 7 | class_name: AcceptanceTester 8 | modules: 9 | enabled: 10 | - Asserts 11 | - \Helper\Acceptance 12 | - PhpBrowser: 13 | # url: &url http://localhost:8080/v1/ # stock testing location 14 | url: &url http://172.17.0.1:8080/v1/ # use this is testing from INSIDE the container 15 | - REST: 16 | depends: PhpBrowser 17 | url: *url -------------------------------------------------------------------------------- /tests/acceptance/AllQueriesActiveModelCept.php: -------------------------------------------------------------------------------- 1 | wantTo('Test query abilities of all api end points'); 11 | 12 | $endpoints = array( 13 | 'addresses', 14 | 'customers', 15 | 'users' 16 | ); 17 | 18 | foreach ($endpoints as $endpoint) { 19 | $I->sendGet("$endpoint?limit=2"); 20 | $I->seeResponseCodeIs(200); 21 | $I->seeResponseIsJson(); 22 | 23 | $newID = $I->grabDataFromResponseByJsonPath("$.data[0].id"); 24 | 25 | // test calling an individual resource 26 | $I->sendGet($endpoint . '/' . $newID[0]); 27 | $I->seeResponseCodeIs(200); 28 | $I->seeResponseIsJson(); 29 | 30 | // test offset 31 | $I->sendGet("$endpoint?limit=2&offset=2"); 32 | $I->seeResponseCodeIs(200); 33 | $I->seeResponseIsJson(); 34 | $I->seeResponseJsonMatchesJsonPath("$.data[0].id"); 35 | 36 | // run searches side loading all records 37 | $I->sendGet("$endpoint?limit=2&offset=2&with=all"); 38 | $I->seeResponseCodeIs(200); 39 | $I->seeResponseIsJson(); 40 | $I->seeResponseJsonMatchesJsonPath("$.included[0].id"); 41 | } -------------------------------------------------------------------------------- /tests/acceptance/_bootstrap.php: -------------------------------------------------------------------------------- 1 |