{"id":1569,"date":"2022-08-30T15:17:37","date_gmt":"2022-08-30T15:17:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/suppressing-the-request-when-running-phpunit-with-kohana-3-2-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:37","modified_gmt":"2022-08-30T15:17:37","slug":"suppressing-the-request-when-running-phpunit-with-kohana-3-2-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/suppressing-the-request-when-running-phpunit-with-kohana-3-2-collection-of-common-programming-errors\/","title":{"rendered":"Suppressing the request when running PHPUnit with Kohana 3.2-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m having trouble correctly setting up unit testing in Kohana 3.2.<\/p>\n<p>I installed PHPUnit. I changed the bootstrap to activate Kohana&#8217;s unittest module. I also changed the index.php file to look like this:<\/p>\n<pre><code>if ( ! defined('SUPPRESS_REQUEST'))\n{\n    echo Request::factory()\n        -&gt;execute()\n        -&gt;send_headers()\n        -&gt;body();\n}\n<\/code><\/pre>\n<p>I created a folder tests in my application folder. In it, I inserted a phpunit.xml file that looks like this:<\/p>\n<pre><code>\n\n    \n        .\/\n    \n\n<\/code><\/pre>\n<p>I am having two problems (the first one is the one I really need an answer to):<\/p>\n<p>1- When I go into tests from the command line and try running phpunit, it seems that SUPPRESS_REQUEST never gets set to true. The Request is executed, and therefore no tests are run. The only way I am able to run the tests successfully is to momentarily comment out the entire Request::factory() line in index.php. Does anyone know how to get around this problem? If I should be adding a define(&#8216;SUPPRESS_REQUEST&#8217;, true) somewhere, where should I do it? I&#8217;m new to Kohana and PHPUnit.<\/p>\n<p>2- PHPUnit complains that the variable REMOTE_ADDR is not set.<\/p>\n<pre><code>PHP Notice:  Undefined index: REMOTE_ADDR in\n\/Users\/**\/Sites\/root\/application\/bootstrap.php on line 76\n<\/code><\/pre>\n<p>This is actually not a huge problem for now as tests still seem to run in spite of this, but I&#8217;m wondering if anyone knows if I should be setting this variable somewhere in specific.<\/p>\n<ol>\n<li>\n<p>In modules\/unittest there is a file called bootstrap.php which works perfectly well with phpunit.<\/p>\n<p>My phpunit.xml which references that bootstrap is this:<\/p>\n<pre><code>\n\n    \n        \n            .\/\n        \n    \n\n<\/code><\/pre>\n<p>Also, for the REMOTE_ADDR problem, when phpunit is running the CLI version of PHP, which I don&#8217;t think has access to a REMOTE_ADDR variable. If you look at the bootstrap from unittest, it does not use http related globals.<\/p>\n<p>I&#8217;m not sure why you have to run Request::factory code in your bootstrap. On my vanilla 3.2 install, the Request::factory code lives in index.php and not bootstrap.php and does not have any reference to SUPRESS REQUEST. You may have some lingering files from a pre-3.2 installation which need cleaning.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 11:52:28. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having trouble correctly setting up unit testing in Kohana 3.2. I installed PHPUnit. I changed the bootstrap to activate Kohana&#8217;s unittest module. I also changed the index.php file to look like this: if ( ! defined(&#8216;SUPPRESS_REQUEST&#8217;)) { echo Request::factory() -&gt;execute() -&gt;send_headers() -&gt;body(); } I created a folder tests in my application folder. In it, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1569","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1569"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1569\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}