Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » PHPUnit not working (thus far) on Oxygen.1(PHPUnit not working (thus far) on Oxygen.1)
PHPUnit not working (thus far) on Oxygen.1 [message #1774793] Thu, 19 October 2017 15:53 Go to next message
Adam Sandler is currently offline Adam SandlerFriend
Messages: 3
Registered: July 2009
Junior Member
Hello:

I just downloaded and started running Oxygen.1.

I also installed Composer and PHPUnit in accordance with Chapter 1, the Windows section, from the documentation:

https://phpunit.de/manual/current/en/phpunit-book.pdf

Back in Eclipse I went to In Eclipse install the packages from http://download.eclipse.org/tools/pdt/updates/latest and installed the "PHP Development Tools" (Note: Under "PHP Development Tools (SDK), "PHP Development Tools (PDT) JUnit Tests" showed up in the "Will not be installed" part of the Solution Details section).

So I went into Project -> Properties -> PHP -> Source Paths -> Include Path -> Libraries,

I clicked Add External PHARs... and pointed the file chooser to the home of where I put PHPUnit, c:\php\latest\phpunit\phpunit.phar.

After that, in the Project Explorer tabbed pane, in the PHP Include Path node of the project tree, I can expand phpunit.phar and see all the packages underneath...

Here's the source code:

CalculatorTest.php

<?php
require 'Calculator.php';

class TestCalculator extends PHPUnit_Framework_TestCase {
    
    private $calculator;
    
    protected function setUp() {
        $this->calculator = new Calculator();
    }
    
    protected function tearDown() {
        $this->calculator = NULL;
    }
    
    public function testAdd() {
        $result = $this->calculator->add(1, 2);
        $this->assertEquals(4, $result);
    }
    
}


Calculator.php

<?php
class Calculator
{
    
    public function add($x, $y)
    {
       return $x + $y;
    }
    
}


For this line in the code:

class TestCalculator extends PHPUnit_Framework_TestCase { 


Eclipse has an error, "Quote:
PHPUnit_Framework_TestCase cannot be resolved to a type
".

Eclipse tells me to change it to PHPUnit_Framework_MockObject_Matcher instead... so I do so...

But when going to Run -> Run As _> PHPUnit Test, this popup is displayed:

"Quote:
Unable to find PHPUnit phar Check PHPUnit configuration
".

Does anyone have any ideas how to get PHPUnit running in Oxygen.1? I've attached a couple of screenshots showing my Eclipse. Suggestions are greatly appreciated. Thanks!
  • Attachment: pic3.jpg
    (Size: 199.56KB, Downloaded 54 times)
  • Attachment: pic4.jpg
    (Size: 319.79KB, Downloaded 48 times)
Re: PHPUnit not working (thus far) on Oxygen.1 [message #1778597 is a reply to message #1774793] Mon, 18 December 2017 11:56 Go to previous message
Eli Coten is currently offline Eli CotenFriend
Messages: 8
Registered: August 2015
Junior Member
It sounds like Eclipse is having trouble finding your PHPUnit PHAR. (This is a separate problem to the one where Eclipse complains that "PHPUnit_Framework_TestCase cannot be resolved to a type". This error has something to do with your include path but won't stop you from running the tests; if I were you I'd revert back to using PHPUnit_Framework_TestCase as PHPUnit_Framework_MockObject_Matcher is not a suitable replacement).

To resolve the error you're seeing you need to go to Window -> Preferences -> PHP -> Tools -> PHPUnit and set the PHPUnit Phar setting to the location of your PHPUnit phar.

Note that the Window -> Preferences might be under a different menu on different platforms, this is the location on Linux.
Previous Topic:How to remove old versions of Eclipse plugins?
Next Topic:Variables in PHPUnit Run Configuration
Goto Forum:
  


Current Time: Fri Jan 19 06:05:19 GMT 2018

Powered by FUDForum. Page generated in 0.01936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software