Solved

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in C:\wamp\www\phpvqp3_scripts\ch14\RectangleTest.php on line 8

Posted on 2014-03-21
3
3,605 Views
Last Modified: 2014-03-22
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd c:\wamp\www\phpvqp_scripts
The system cannot find the path specified.

C:\Windows\system32>cd c:\wamp\www\phpvqp_script
The system cannot find the path specified.

C:\Windows\system32>cd c:\wamp\www\phpvqp3_scripts

c:\wamp\www\phpvqp3_scripts>cd ch14

c:\wamp\www\phpvqp3_scripts\ch14>phpunit rectangletest
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: N
o such file or directory in C:\Users\Acer\AppData\Roaming\PEAR\pear\PHPUnit\Auto
load.php on line 64

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No suc
h file or directory in C:\Users\Acer\AppData\Roaming\PEAR\pear\PHPUnit\Autoload.
php on line 64
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoloa
d.php' (include_path='.;C:\Program Files (x86)\NuSphere\PhpED\php54\..\include_l
ib') in C:\Users\Acer\AppData\Roaming\PEAR\pear\PHPUnit\Autoload.php on line 64

Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php
' (include_path='.;C:\Program Files (x86)\NuSphere\PhpED\php54\..\include_lib')
in C:\Users\Acer\AppData\Roaming\PEAR\pear\PHPUnit\Autoload.php on line 64

c:\wamp\www\phpvqp3_scripts\ch14>

Open in new window



does spl need to be installed?




running rectangletest from browser
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in C:\wamp\www\phpvqp3_scripts\ch14\RectangleTest.php on line 8


rectangle.php
<?php # Script 7.6 - Rectangle.php
/*  This page defines the Rectangle class.
 *  The class contains two attributes: width and height.
 *  The class contains five methods: 
 *  - __construct()
 *  - setSize()
 *  - getArea()
 *  - getPermeter()
 *  - isSquare()
 */
 
class Rectangle {
    
    // Use the debug trait:
    //use tDebug;

    // Declare the attributes:
    public $width = 0;
    public $height = 0;

    // Constructor:
    function __construct($w = 0, $h = 0) {
        $this->width = $w;
        $this->height = $h;
    }
    
    // Method to set the dimensions:
    function setSize($w = 0, $h = 0) {
        $this->width = $w;
        $this->height = $h;
    }
    
    // Method to calculate and return the area:
    function getArea() {
        return ($this->width * $this->height);
    }
    
    // Method to calculate and return the perimeter:
    function getPerimeter() {
        return ( ($this->width + $this->height) * 2 );
    }
    
    // Method to determine if the rectange 
    // is also a square.
    function isSquare() {   
        if ($this->width == $this->height) {
            return true; // Square
        } else {
            return false; // Not a square
        }
        
    }

} // End of Rectangle class.

Open in new window



rectangletest.php
<?php # RectangleTest.php - Script 14.3 #2
// This page defines the RectangleTest class.

// Need the Rectangle class in order to work:
require('Rectangle.php');

// Define the class:
class RectangleTest extends PHPUnit_Framework_TestCase {
    
    // For storing the Rectangle object:
    protected $r;
    
    // Create an object to use:
	function setUp() {
	    $this->r = new Rectangle(8,9);
	}

    // Test the getArea() method:
	function testGetArea() {
	    $this->assertEquals(72, $this->r->getArea());
	}
    
    // Test the getPerimeter() method:
    function testGetPerimeter() {
        $this->assertEquals(34, $this->r->getPerimeter());
    }

    // Test the isSquare() method:
    function testIsSquare() {
        
        // Should not be a square in this case!
        $this->assertFalse($this->r->isSquare());
        
        // Make it a square and test again:
        $this->r->setSize(5,5);
        $this->assertTrue($this->r->isSquare());

    }

    // Test the setSize() method:
    function testSetSize() {
        $w = 5;
        $h = 8;
        $this->r->setSize($w, $h);
        $this->assertEquals($w, $this->r->width);
        $this->assertEquals($h, $this->r->height);
    }
    
} // End of RectangleTest class.

Open in new window

0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
duncanb7 earned 500 total points
ID: 39946945
Probably it is caused  by the incorrect  file path, please take a look at $filepath that
whether is matched to your exact directory file path or not , and add the following code in your rectangletest.php that may  solve the issue and take care of "/" slash on your directory path

$filepath = realpath (dirname(__FILE__));
echo $filepath."====\n";
require($filepath.'/Rectangle.php');

Duncan
0
 

Author Closing Comment

by:rgb192
ID: 39948006
okay, you allowed me to see that this is a pear/phpunit error which was fixed with installation of pear/phpunit.
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39948204
thanks for your pt

have a nice day

Duncan
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now