1

I am experiencing a very weird issue.

I have two classes, one is in App\Projects\github\Units\github_login and the other is App\Projects\github\Schema\github_login

The Schema file is just a scheme which shows the skeletal structure of the file App\Projects\github\Units\github_login.

In fact, it should never ever get loaded and executed, it is just for humans.

However, PHP always executes this file instead of App\Projects\github\Units\github_login

namespace App\Http\Controllers;

use App\Models\Selenium;
use App\Models\Project;
use App\Projects\github\Units\github_login;

class PlayController extends BasePlayController
{
    private $github_login;

    function __construct()
    {
        parent::__construct();
        $this->github_login = new github_login();
    }

    /**
    * Play a testcase X times.
    *
    * @param string $Project
    * @param string $Unit
    * @param string $Scenario
    * @param string $Testcase
    * @param int $Times
    * @param int $Delay
    * @return /Illuminate/View/View
    */
    public function PlayCase($Project, $Unit, $Scenario, $Testcase, $Times=1, $Delay=3)
    {
        $SeleniumObj = $this->Selenium;

        $Unit =  $Project .'_'. $Unit;

        switch ($Project) {
            case 'github':
                switch ($Unit) {
                    case 'github_login':
                        switch ($Scenario) {
                            case 'standard':
                                 $this->callCase(array($this->github_login, 'standard'), $Testcase, $Times, $Delay);
                                break;
                            default:
                                $SeleniumObj->logMessage[$SeleniumObj->index]['TestcaseTitle'] = $Scenario;
                                $SeleniumObj->setMessage(2,"Das Szenario '<strong>". $Scenario ."</strong>' existiert nicht!", '');
                        }
                        break;
                }
                break;
            default:
                $SeleniumObj->setTitle('Projekt existiert nicht.');
                $SeleniumObj->setMessage(2,'Das Projekt <strong>'. $Project .'</strong> existiert nicht. (Fix: einfach neuen Testfall anlegen)', '');
        }

        return view('show.report')->with('driver',        $SeleniumObj->driver)
                                  ->with('ScenarioName',  $Scenario)
                                  ->with('logMessage',    $SeleniumObj->logMessage)
                                  ->with('execScriptRet', $SeleniumObj->execScriptRet)
                                  ->with('screenshot',    $SeleniumObj->screenshot)
                                  ->with('PlayAll',       false);
    }

As you can see in the screenshot, it even loads the right one, but how on earth does it execute the one in folder Schema?

enter image description here

I am making selenium tests btw and use the github login page for start.

UPDATE:

BasePlayController - callCase:

namespace App\Http\Controllers;

use App\Models\Selenium;

class BasePlayController
{
    public $Selenium;

    function __construct()
    {
        $this->Selenium = new Selenium();
    }

    public function callCase($thisFunction, $Testcase, $Times=1, $Delay=1)
    {
        $SeleniumObj = $this->Selenium;

        if (is_numeric($Times)) {
            for($i = 1; $i <= $Times; $i++) {

                $thisFunction($SeleniumObj, $Testcase);
                sleep($Delay);
            }
        } else {
            $SeleniumObj->logMessage[$SeleniumObj->index]['TestcaseTitle'] = 'Falscher Parameter für Times.';
            $SeleniumObj->setErrorMessage("Times muss eine Zahl sein! (Gegeben: '<strong>". $Times ."</strong>')", '');
        }
    }

 ...

UPDATE 2

Autloader Entry in vendor\composer\autoload_classmap.php

'App\\Projects\\github\\Units\\github_login' => $baseDir . '/app/Projects/github/Schema/github_login.php',

I tried to change it to

'App\\Projects\\github\\Units\\github_login' => $baseDir . '/app/Projects/github/Units/github_login.php',

but it made no difference.

14
  • Only the default laravel autoloader. Commented Jul 16, 2018 at 7:35
  • It is unclear, how do you understand that another file is included. Commented Jul 16, 2018 at 7:38
  • Because a syntax error is thrown and It only works if I fix it in the file App\Projects\github\Schema\github_login. Even though the error is in both files. Commented Jul 16, 2018 at 7:39
  • 1
    What does BasePlayController do? Does it use this file? Commented Jul 16, 2018 at 7:39
  • 1
    Maybe Units\github_login uses Schema\github_login ? Commented Jul 16, 2018 at 7:40

2 Answers 2

1

Assuming you have 2 files declaring the same class. Composer is scanning a directory finding classes and classmapping them to their location. It just happens to be since there can only be one by key that its pointing the the duplicate class in Schema. Would be my quick thoughts without digging into the internals.

The file says it is in X namespace and the classname is Y ... that is what it is regardless of where it physically exists.

I guess you can not have 2 files declaring the same class like that (anywhere in a folder that gets classmapped), or make the duplicate not a valid php file for use, maybe making it .phps. ... and redump the autoload.

Sign up to request clarification or add additional context in comments.

Comments

0

I found the cause. I had to change the autoloader entry in vendor\composer\autoload_static.php from

'App\\Projects\\github\\Units\\github_login' => __DIR__ . '/../..' . '/app/Projects/github/Schema/github_login.php',

to

'App\\Projects\\github\\Units\\github_login' => __DIR__ . '/../..' . '/app/Projects/github/Units/github_login.php',

But I wonder why I have to do this manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.