Hi I am currently running through the ZF2 User Guide trying to run a PHPUnit Test on the skeleton application as outlined here http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html.
But even though I have not edited the Module and have copied all the files from the tutorial every time I run the PHPUnit Test in Zend Studio I get this error
Error:
Fatal error: Class 'ApplicationTest\Bootstrap' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\exerciseDB\module\Application\test\ApplicationTest\Controller\IndexControllerTest.php on line 24
But when I click on the Bootstrap::getServiceManager(); on line 24 Zend Studio takes me to the correct method.
File Stucture:
module
|_Application
|_config
|_language
|_src
|_test
|_ApplicationTest
| |_Controller
| |_IndexControllerTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
Can anyine tell me where I am going wrong?
This was a really annoying bug that is somewhat of an irritation. Your phpunit config seems to be changed slightly from the one on the skeleton application. To give you direct answer that fixed my issue I did the following...
module
|_Application
|_config
|_language
|_src
|_tests
|_ZendApplicationModule
| |_Framework
| |TestCase.php
| |_IndexControllerTest.php
| |_SampleTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
With the base setup as outlined above from the skeleton APP I had to add
require_once 'Framework/TestCase.php';
To SampleTest.php
For your actual fix you will need to require_once the file that is generating the issue. That should fix it.
Also make sure to update your autoload_classmap.php
I ran into the same issue where phpunit was not seeing my "module/Application/test/phpunit.xml.dist" file (I had it miss-spelled)
Try adding the file directly to the command line:
phpunit --bootstrap Bootstrap.php .
I had the issue as well.
I solved it by running phpunit from the root of my ZF2 project with the following arguments:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
One can also specify the Test suite to use:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
./module/Rest/test/RestTest/Controller/RestControllerTest.php
more details here
Related
I've a project I try to run it but I am getting a following error:
PHP Fatal error: Class 'Dotenv' not found in `/home/maras/Documents/eCodile/debtorcare/server/bootstrap/app.php on line 5`
I'm struggling with this error during trying to execute a php artisan start I tried to reinstall all dependencies but it didn't work.
I've just tried to run some commands based on other similar problems I found in the Internet but any of them worked. I tried ie:
composer require vlucas/phpdotenv --prefer-dist
Ive got a file .env.
This is a file where error is placed:
<?php
require_once __DIR__.'/../vendor/autoload.php';
Dotenv::makeMutable();
Dotenv::load(__DIR__.'/../');
Dotenv::makeImmutable();
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
Is it possible the error is connected with wrong configuration of a database or phpMyAdmin? Or maybe Ive got .env placed in wrong place?
I try to run this project in development.
I guess the cwd was changed while you're running the command. make sure that composer.json, .env, "vendor/autoload.php" can be loaded from the project root.
maybe you need to run "composer dump-autoload" after the Dotenv installation,
As c9s suggests, Check to make sure that you are loading an existing vendor/autoload.php with something like:
$vendor_audoload = __DIR__.'/../vendor/autoload.php';
print $vendor_audoload;
if(file_exists($vendor_audoload)){
print " Exists!";
} else {
print " Does not exist!";
}
Hi i am quit new in Laravel PHPUnit, getting the following error :
Laravel : phpunit cannot open file ExampleTest.php
I don't have idea why i am getting this error. I installed PHPUnit globally and when i run "phpunit" in terminal it runs fine. But I want to run it on specific file like :
phpunit ExampleTest
Thanks In Advance.
Make sure you are on the project root and referencing the file inside the tests folder.
Example:
phpunit tests/ExampleTest.php
I am working in Windows. Try to use the full path:
C:\Desktop\code\blog\vendor\bin>phpunit C:\Desktop\code\blog\tests\Feature\ExampleTest.php
PHPUnit 7.2.6 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 1.46 seconds, Memory: 10.00MB
OK (1 test, 1 assertion)
This started happening when I upgrade phpUnit, I had to update phpStorm to fix it.
try it like this:
vendor\bin\phpunit tests\Unit\ExampleTest.php
it will work surly
but first install phpunit globally.
Maybe you call wrong to your test.
Try like this :
php artisan test --filter YourTestClassName
I've started learning how to use PHPUnit. However, I'm facing a problem which I have no clue how to solve.
I have a folder called lessons and inside there is a composer.json which I installed PHPUnit with.
The output resulted in a folder called vendor and a sub-folder called bin which has the phpunit file in it.
In the cmd I typed: cd c:/xampp/htdocs/lessons/vendor/bin. Now the cmd folder sets to the same folder as phpunit. I've created a directory in lessons which I called tests (lessons/tests) which I store all of my tests in. I've created a file called PracticeTest.php with a very simple test script in it.
When I go back to the cmd and type phpunit tests I get cannot open file tests.php When I try to type phpunit PracticeTest I get cannot open file PracticeTest.php. When I try phpunit tests/PracticeTest (with .php or without) I get the same error that the file could not be opened.
My suspicious that it has something to do with that face that the cmd is pointing at the lessons/vendor/bin directory, but I'm not sure if it is really the problem or how to fix it.
just to arrange the paths:
lessons\vendor\bin\
lessons\tests\
lessons\tests\PracticeTest.php
Thanks in advance!
Go to path project:
D:\>cd www
D:\wwww>cd lessons
And execute:
D:\www\lessons>vendor\bin\phpunit tests
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
.....E.
Time: 1.34 seconds, Memory: 5.50MB
There was 1 error:
1) UserTest::it_should_be_able_to_construct
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert
:assertInstanceOf() must be a class or interface name
D:\www\lessons\tests\UserTest.php:10
FAILURES!
Tests: 7, Assertions: 4, Errors: 1.
It Works!!!!
This is what worked for me.
vendor/bin/phpunit ./tests/PracticeTest
I was getting the same, but if you type phpunit then tab you will see what directory you are in and it should autosuggest. Then navigate to your test file.
I had include_path sections separated by comma. It has to be semicolon on Windows.
I have created a phpunit.bat in the root folder of my project containing
#ECHO OFF SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit php "%BIN_TARGET%" %*
Now it works.
Running phpunit tests using PhpStorm.
Receiving this error:
/usr/local/php5/bin/php
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
--configuration /Users/psteinheuser/unity/test/phpunit.xml DatabaseDumperTest
/Users/psteinheuser/unity/test/DatabaseDumperTest.inc Testing started
at 11:36 AM ...
Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Call Stack:
0.0013 340096 1. {main}() /private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php:0
PHP Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Have found previous posts which have said this is fixed, though I seem to have the correct versions where it should work.
PHPStorm 7.1.3
phpunit 3.7.28
php 5.4.24
The OS is Mac 10.9.2
Have removed and re-installed PHPStorm, upgraded php, re-installed phpunit, restarted apache, rebooted, scratched my head, etc.
Running the phpunit tests manually from the terminal, works fine.
Looking at Preferences within PHpStorm, it seems to be pointing to phpunit correctly.
I'm thinking it's a permission or path issue, but I don't know where to look next.
Appreciate any input or direction.
In PHPStorm, the only way I was able to solve this was by manually updating the contents of the jar file where this error exists.
We're both on Mac OSX 10.9, so these instructions should work for you.
Begin by making a copy of the existing jar file:
cp /Applications/PhpStorm.app/plugins/php/lib/php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar.orig
Now, create a temporary directory to hold your jar file's contents and extract
mkdir ~/jarfiles
cd ~/jarfiles
jar xf /Applications/PhpStorm.app/plugins/php/lib/php.jar
Once extracted, you'll need to edit the phpunit.php file to add the missing method stub
vi scripts/phpunit.php
Around line 310 in my file is a class 'IDE_PHPUnit_Framework_TestListener'. Insert the following method stub:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}
Now just re-pack your jar and replace it into your PhpStorm:
jar cf0 php.jar ./*
mv php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar
That fixed it for me. Hope it fixes it for you too. Good luck!
I am trying to create a controller in cakephp(1.3) using console. I am using windows XP and XAMPP.
My current cake console settings below
C:\xampp\htdocs\cake\apressblog\cake\console>cake
♀ Welcome to CakePHP v1.3.4 Console
--------------------------------------------------------------- Current Paths: -app: console
-working: C:\xampp\htdocs\cake\apressblog\cake\console
-root: C:\xampp\htdocs\cake\apressblog\cake
-core: C:\xampp\htdocs\cake\apressblog
Changing Paths: your working path
should be the same as your application
path to change your path use the
'-app' param. Example: -app
relative/path/to/myapp or -app
/absolute/path/to/myapp
Available Shells: acl [CORE]
i18n [CORE]
api [CORE]
schema [CORE]
bake [CORE]
testsuite [CORE]
console [CORE]
To run a command, type 'cake
shell_name [args]' To get help on a
specific command, type 'cake
shell_name help'
C:\xampp\htdocs\cake\apressblog\cake\console>-app
c:\xampp '-app' is not recognized as
an internal or external command,
operable program or batch file.
C:\xampp\htdocs\cake\apressblog\cake\console>
what are the path settings I need to set for creating a controller from console ?
I tried to change the app path but, when I type command cake It goes app directory to console,
Could you please help me to solve this issue
when I try to create a controller I am getting the following error :
C:\xampp\htdocs\cake\apressblog\cake\console>cake bake controller news
♀
Welcome to CakePHP v1.3.4 Console
---------------------------------------------------------------
App : console
Path: C:\xampp\htdocs\cake\apressblog\cake\console
---------------------------------------------------------------
Creating file C:\xampp\htdocs\cake\apressblog\cake\console\controllers\news_cont
roller.php
Wrote `C:\xampp\htdocs\cake\apressblog\cake\console\controllers\news_controller.
php`
You can download SimpleTest from http://simpletest.org
Bake is detecting possible fixtures..
Warning: include_once(C:\xampp\htdocs\cake\apressblog\cake\console\config\databa
se.php): failed to open stream: No such file or directory in C:\xampp\htdocs\cak
e\apressblog\cake\libs\model\connection_manager.php on line 23
Warning: include_once(): Failed opening 'C:\xampp\htdocs\cake\apressblog\cake\co
nsole\config\database.php' for inclusion (include_path='.;\xampp\php\PEAR') in C
:\xampp\htdocs\cake\apressblog\cake\libs\model\connection_manager.php on line 23
Fatal error: ConnectionManager::getDataSource - Non-existent data source default
in C:\xampp\htdocs\cake\apressblog\cake\libs\model\connection_manager.php on li
ne 102
C:\xampp\htdocs\cake\apressblog\cake\console>
You need to create your database.php file in the config folder so that Cake knows what database to connect to for the models.
Once you have done this you need to create your database schema and then bake the model for it.
I'd been having the same problem and was googling when I stumbled upon this. I was getting the same 'Warning: include_once...' error as you did.
I figured out this was happening only when I ran the 'cake bake' command from the ..\cake\console\ folder like you did.
So here's what fixed this issue for me. I added path to the console folder to my environment variables. Now I could call the cake bake command from anywhere.
Then I changed directory to your app folder e.g. ...\htdocs\myCakeWebsite\app
Then run 'cake bake' command! It worked fine from then on.
sources: http://www.youtube.com/watch?v=xvJH0wTlRg