PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] Composer autoloader can't find PHPUnit when running tests

 February 22, 2022     composer-php, php, phpunit     No comments   

Issue

I am updating a legacy PHP project to use composer, and implementing PHPUnit. unfortunately I have run into a few issues. When running PHPUnit

Fatal error: Class 'PHPUnit_Framework_TestCase' not found

composer.json

{
    "require": {
        "phpunit/phpunit": "^8.0",
        "phpoffice/phpspreadsheet": "^1.6"
    },
    "autoload": {

        "psr-4": {"Biz\\": "src/php/Classes"}
    }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
         bootstrap="vendor/autoload.php"
         verbose="true">
  <testsuites>
  <testsuite name="Random Tests">
    <directory>./src/test/random/*Test.php files</directory>
  </testsuite>
</testsuites>
</phpunit>

Directory structure

directory structure

Command line being executed

$ ./vendor/bin/phpunit ./src/test/random/SampleTest.php

I am running it using git-bash. executing from visual studio code gives the same result. I have read, implemented the issue as described in Autoloading classes in PHPUnit using Composer and autoload.php

Test Case

<?php

class SampleTest extends \PHPUnit_Framework_TestCase {
    public function testUserClassInheritance(){
        global $mysqlConn;
        echo "testing";
        $this->assertTrue(true);

        $user = new Bruger;
    }
}

Solution

PHPUnit_Framework_TestCase does not exist in PHPUnit version 8, which is your minimum specified version. As of (I think) PHPUnit version 5, it's using namespaces, so your test case should be named \PHPUnit\Framework\TestCase.

You can downgrade your PHPUnit requirement to an older version, or (preferably) update your tests to meet the new naming style.



Answered By - Alex Howansky
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing