1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | defined('BASEPATH') OR exit('No direct script access allowed'); |
||||
4 | |||||
5 | use PHPUnit\Framework\TestCase; |
||||
0 ignored issues
–
show
|
|||||
6 | |||||
7 | class BasicAuthTest extends TestCase { |
||||
8 | /** |
||||
9 | * Code Igniter Instance. |
||||
10 | * @var object |
||||
11 | */ |
||||
12 | private static $ci; |
||||
13 | /** |
||||
14 | * Package name for simplicity |
||||
15 | * @var string |
||||
16 | */ |
||||
17 | private const PACKAGE = "francis94c/ci-rest"; |
||||
18 | |||||
19 | /** |
||||
20 | * Prerquisites for the Unit Tests. |
||||
21 | * |
||||
22 | * @covers JWT::__construct |
||||
23 | */ |
||||
24 | public static function setUpBeforeClass(): void { |
||||
25 | self::$ci =& get_instance(); |
||||
0 ignored issues
–
show
The function
get_instance was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
26 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
||||
27 | self::$ci->load->helper("url"); |
||||
28 | $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql')); |
||||
0 ignored issues
–
show
|
|||||
29 | self::assertTrue(count($queries) > 0); |
||||
30 | self::$ci->load->database(); |
||||
31 | foreach ($queries as $query) { |
||||
32 | self::$ci->db->query($query); |
||||
33 | } |
||||
34 | // Verify that URI can be modified. |
||||
35 | self::$ci->uri->set_uri_string("a/uri"); |
||||
36 | self::assertEquals("a/uri", uri_string()); |
||||
0 ignored issues
–
show
The function
uri_string was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
37 | // Everything about this library, happens in it's connstructors. |
||||
38 | // Some static PHPUnit assertions will take place in the rest.php file |
||||
39 | // traditionally provided by the user and loaded from application/config by |
||||
40 | // default. |
||||
41 | // However, for the purpose of this test, we are going to Hack Code CodeIgniter |
||||
42 | // with a Splint Config variable to allow us load config files from where |
||||
43 | // ever we want. This happens below. |
||||
44 | self::$ci->load->add_package_path(APPPATH . 'splints/' . self::PACKAGE . "/phpunit/"); |
||||
0 ignored issues
–
show
|
|||||
45 | //self::$ci->config->set_item('st_config_path_prefix', '../splints/' . self::PACKAGE . "/phpunit/config/"); |
||||
46 | } |
||||
47 | /** |
||||
48 | * [testBasicAuthentication description] |
||||
49 | */ |
||||
50 | public function testBasicAuth():void { |
||||
51 | // Simulate Request To 'basic/auth' |
||||
52 | self::$ci->uri->set_uri_string("basic/auth"); |
||||
53 | // Simulate Basic Authorization |
||||
54 | $_SERVER['PHP_AUTH_USER'] = "francis94c"; |
||||
55 | $_SERVER['PHP_AUTH_PW'] = "0123456789"; |
||||
56 | self::$ci->load->splint(self::PACKAGE, '+REST', null, 'basic_rest_1'); |
||||
57 | $this->assertEquals(1, self::$ci->basic_rest_1->userId); |
||||
58 | $_SERVER['PHP_AUTH_PW'] = "012345678901234567890"; |
||||
59 | self::$ci->config->set_item('expected_uri', 'basic/auth'); |
||||
60 | self::$ci->config->set_item('expected_auth', RESTAuth::BASIC); |
||||
61 | $this->expectExceptionMessage('Error ' . RESTResponse::UN_AUTHORIZED . ' in ' . RESTAuth::BASIC); |
||||
62 | self::$ci->load->splint(self::PACKAGE, '+REST', null, 'basic_rest_2'); |
||||
63 | } |
||||
64 | /** |
||||
65 | * [tearDownAfterClass description] |
||||
66 | */ |
||||
67 | public static function tearDownAfterClass(): void { |
||||
68 | self::$ci->db->empty_table("api_keys"); |
||||
69 | self::$ci->db->empty_table("users"); |
||||
70 | self::$ci->db->empty_table("rest_api_rate_limit"); |
||||
71 | self::$ci->load->dbforge(); |
||||
72 | self::$ci->dbforge->drop_table("api_keys"); |
||||
73 | self::$ci->dbforge->drop_table("users"); |
||||
74 | self::$ci->dbforge->drop_table("rest_api_rate_limit"); |
||||
75 | self::$ci->db->close(); |
||||
76 | } |
||||
77 | } |
||||
78 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths