mock undefined index: query

65 views
Skip to first unread message

arava-el

unread,
Jul 15, 2019, 9:59:55 AM7/15/19
to Fat-Free Framework
Hello everyone! I have a problem with mock()

The error is:
Undefined index: query [/var/www/project.in/lib/base.php:1288]
[unittest/unittest.php:16] Base->mock()

Handler:
$f3->mock('POST /api/v1/phones');

So, I am trying to test my route with POST. For this reason, I have made a file unittest.php with mock(), but the error has occured in the result.
On the line 1288 of base.php I've made var_dump of $url variable, here is the result:
array(1) {
  ["path"]=>
  string(26) "/api/v1/phones"
}

As you can see there is no index key, weird behavior for me... what I am doing wrong? Thx

ikkez

unread,
Jul 15, 2019, 3:08:11 PM7/15/19
to Fat-Free Framework
Which F3 version is this?

arava el

unread,
Jul 15, 2019, 3:10:32 PM7/15/19
to ikkez via Fat-Free Framework, Fat-Free Framework
VERSION='3.6.2-Release'

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/ce49839f-fb51-4c91-9731-10644afd656e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

arava el

unread,
Jul 16, 2019, 6:08:00 AM7/16/19
to ikkez via Fat-Free Framework, Fat-Free Framework
I am still get an error... any suggestions please

xfra35

unread,
Jul 16, 2019, 11:14:24 AM7/16/19
to Fat-Free Framework
That's strange, as if the silent operator (@) is getting ignored.

Can you tell us which PHP version you're running and which extensions are loaded?

print_r(get_loaded_extensions());


arava el

unread,
Jul 16, 2019, 11:18:32 AM7/16/19
to xfra35 via Fat-Free Framework, Fat-Free Framework
$ php -v
PHP 7.2.19-0ubuntu0.18.04.1 (cli) (built: Jun  4 2019 14:48:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.19-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies



Array ( [0] => Core [1] => date [2] => libxml [3] => openssl [4] => pcre [5] => sqlite3 [6] => zlib [7] => bcmath [8] => bz2 [9] => calendar [10] => ctype [11] => curl [12] => dba [13] => dom [14] => hash [15] => fileinfo [16] => filter [17] => ftp [18] => gd [19] => gettext [20] => SPL [21] => iconv [22] => session [23] => intl [24] => json [25] => ldap [26] => mbstring [27] => mcrypt [28] => standard [29] => mysqlnd [30] => mysqli [31] => PDO [32] => pdo_mysql [33] => pdo_pgsql [34] => pdo_sqlite [35] => Phar [36] => posix [37] => Reflection [38] => imap [39] => shmop [40] => SimpleXML [41] => soap [42] => sockets [43] => exif [44] => sysvsem [45] => sysvshm [46] => tokenizer [47] => wddx [48] => xml [49] => xmlreader [50] => xmlrpc [51] => xmlwriter [52] => xsl [53] => zip [54] => apache2handler )

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.

xfra35

unread,
Jul 16, 2019, 12:15:31 PM7/16/19
to Fat-Free Framework
I was searching for the scream extension, that disables the silent operator, but you don't have it.

There are two unexplained things in your case:

1) the silent operator is getting ignored
2) even without the silent operator, PHP shouldn't choke on this specific line since the framework sets the error_reporting to (E_ALL|E_STRICT)&~(E_NOTICE|E_USER_NOTICE) => notice how the E_NOTICE is excluded

Or did you manually set the error reporting to something else?

arava el

unread,
Jul 16, 2019, 2:02:06 PM7/16/19
to xfra35 via Fat-Free Framework
@xfra35, thx dude, I did it finally... But I have to go now, thats why I will post my solution a little bit later...
Have a nice time! Thanks one more time :-)

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.

arava el

unread,
Jul 16, 2019, 4:20:52 PM7/16/19
to xfra35 via Fat-Free Framework, Fat-Free Framework
So, finally I've done it
The problem was with `error_reporting` at this part of code:
set_error_handler (
    function($errno, $errstr, $errfile, $errline) {
        throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
    }
);

I added this part when I worked with try/catch few weeks ago, because even I set DEBUG=0 try/catch functionality did not work for me!
And because of that code, PHP did not show me the error while I have been worked with mock():
Unable to open
[tmp/50zwu7qhi6i6.1svfyqxupkhdi.php:12] Preview->render()

That's because I have tried to test mock() in the BaseController that has `afterroute` method, that's why php has tried to display html part, and as the result - error occurred.
So, I have rewritten some part of code,  and now F3 allows me to use mock() for unit testing without error.

Thanks @xfra35 for right direction 😎

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.

xfra35

unread,
Jul 17, 2019, 4:56:18 AM7/17/19
to Fat-Free Framework
You're welcome, thanks for the feedback.

Concerning errors, they are catchable since PHP7. See:

try {
    intdiv
(1,0);
} catch (Error $e) {
    echo $e
->getMessage();
}

But that only applies to errors (not warnings nor notices).

But maybe did you precisely add the set_error_handler statement in order to catch warnings and notices?

arava el

unread,
Jul 17, 2019, 5:16:13 AM7/17/19
to xfra35 via Fat-Free Framework, Fat-Free Framework
@xfra35 I was looking for the solution to catch all errors, warnings and notices.

For example I have a route `/api/v1/param`
In my CLI I make `php www/index.php /api/v1/param` (it's okay)
however If I will do `php www/index.php /api/v1/` F3 will redirect me to the method that consist of $f3->error('404') but,
console will display me something like this:
HTTP 404 (GET /404)
[controllers/BaseController.php:43] Base->error()
[www/index.php:9] Base->run()

I have played around DEBUG with 0,1,2,3 values, but I still get file names and errors! That's why I have used the code with set_error_handler.
So, how can I display only `HTTP 404 (GET /404)` in such cases?

xfra35

unread,
Jul 17, 2019, 7:14:10 AM7/17/19
to Fat-Free Framework
You can define a custom ONERROR handler:

$f3->ONERROR=function($f3) {
 
if ($f3->CLI) {
   
// handle errors in CLI mode, for ex:
    echo
'Command not found. Usage: etc.', PHP_EOL;
   
exit(1);
 
} else {
   
// use default handler otherwise
   
return FALSE:
 
}
};

Reply all
Reply to author
Forward
0 new messages