J
J
John Bjornsen2018-12-03 20:57:21
PHP
John Bjornsen, 2018-12-03 20:57:21

Why is external file not included in phpunit?

There is the following directory structure in the project root:
--core
----static-info
--------GettingStaticInfo.php
--tests
----static-info
--------GettingStaticInfoTest.php
--vendor GettingStaticInfo.php
file

<?php

//namespace Enkelad\Mednotifier\StaticInfo;

require_once '../../vendor/autoload.php';

use DiDom\Document;
use JonnyW\PhantomJs\Client;

class GettingStaticInfo
{
...
public function form_url(int ...$args)
{...}
...

GettingStaticInfoTest.php file
<?php
declare (strict_types = 1);

//namespace Tests\StaticInfo;

use PHPUnit\Framework\TestCase;
//use Enkelad\Mednotifier\StaticInfo\GettingStaticInfo;

require_once '../../core/static-info/GettingStaticInfo.php';

final class GettingStaticInfoTest extends TestCase
{
    public function testFormUrlNoArg() : void
    {
        $staticInfo = new GettingStaticInfo();
        $url = $staticInfo->form_url();
        $this->assertEquals('http://jonnyw.me', $url);
    }
}

The problem is that require_once '../../core/static-info/GettingStaticInfo.php'; throws an error when running the test:
5c056a77b3666204182142.png
I know that you can somehow use the namespace for the class under test, then add it to autoload, but I still have problems understanding these topics, so I would like to use a simple solution with the usual require_once.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Nesmeyanov, 2018-12-03
@Bjornsen

__DIR__ , Carl, __DIR__ constant

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question