How do I hide '#StandWithUkraine' in PHPUnit 9.5.20? - php

I have recently upgraded to PHPUnit 9.5.20 and noticed that it is printing #StandWithUkraine for every test run. Eg.
Testing started at 10:01 am ...
Running in local mode
PHPUnit 9.5.20 #StandWithUkraine
Time: 00:01.141, Memory: 24.00 MB
OK (1 test, 4 assertions)

I guess you would have to edit actual source code of the package, and that seems not recommended.
But the banner is located in phpunit / src / TextUI / TestRunner.php on line 322 - 331
I guess removing it would do the trick, however I haven't tried it and don't recommend.
The banner is also mentioned in a few other files. I've tracked down a commit made by the package author so you can see where the banner is mentioned.
Commit by author

Related

What are the correct Codeception (Selenium server, chromedriver) troubleshooting procedures for mac/php?

Since there is no official troubleshooting information, it is an uphill struggle for anyone without a more complete knowledge of working with similar systems to install.
I want to address issues specifically for OSX Catalina and the Selenium server/Chromedriver configuration and put them all in one place. I'll also include my problem at the end.
It seems to me that most of the problems revolve around:
An incorrect installation of either Selenium, Codeception or Chromedriver
Conflicting versions of the above (or php?)
Problems with the port the Selenium server runs on
Coding mistakes: typos, old code etc
Lack of knowledge of terminal/java commands
Path problems
Anything I don't know about/my problem
I'll start with the things I have learnt along the way, please help to fill in the gaps or correct anything I state below if you are able.
Incorrect installation
Installing via homebrew seems the most foolproof way.
Selenium
brew install selenium-server-standalone
Chromedriver
brew tap homebrew/cask
brew cask install chromedriver
Then you can run brew doctor to check installation is okay and follow instructions or google issues. More brew commands.
Check conflicting versions
Installed Google Chrome and Chromedriver should be the same version.
Check Chrome by going to "Chrome" at the top left of the app and the "about Google Chrome".
Check Chromedriver by running brew info chromedriver
Port problems
You might have an old server running on a port you're trying to use. Shut it down going to this page in google chrome.
http://localhost:<port number>/selenium-server/driver?cmd=shutDownSeleniumServer
You can specify the port you run Selenium in terminal using the -port flag. Like this
java -jar <location of your server> -port 8090
Then match this in your acceptance.suite.yml config file
url: 'http://localhost:<port number>/wd/hub'
Coding mistakes in config file
The most common ones I've seen is having a slash at the end of the line of code above or not including '/wd/hub'
Formatting is like so:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://192.168.88.100:<port number>/wd/hub'
browser: chrome
- \Helper\Acceptance
And to format extensions (automatically run) is like this:
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
Lack of knowledge of terminal/java commands
Run a codeception test in terminal using
php vendor/bin/codecept run acceptance --steps
You must have first used
cd <location of your code>
Paths
I don't know how to go about checking paths are configured correctly. (are they inside config files that point to the other programs?) but I keep seeing hints of them scattered around.
My Issue
From below log, I think that chromedriver is loading and there is something happening in the browser, but it does not load my website. Instead it loads the page below. Help greatly appreciated!
Log:
Codeception PHP Testing Framework v4.1.8
Powered by PHPUnit 9.4.2 by Sebastian Bergmann and contributors.
Running with seed:
Acceptance Tests (1) --------------------------------------------------------------------------------------------------
[RunProcess] Starting chromedriver
QuizCest: New user_complete quiz
Signature: QuizCest:newUser_completeQuiz
Test: tests/acceptance/QuizCest.php:newUser_completeQuiz
Scenario --
I am on page "/"
I see "Fragrant"
FAIL
-----------------------------------------------------------------------------------------------------------------------
[RunProcess] Stopping chromedriver
Time: 00:02.653, Memory: 10.00 MB
There was 1 failure:
---------
1) QuizCest: New user_complete quiz
Test tests/acceptance/QuizCest.php:newUser_completeQuiz
Step See "Fragrant"
Fail Failed asserting that on page /wd/hub/static/resource/hub.html
--> Sessions
Create Session | Refresh Sessions
Chrome
e999201a1381fb966c9d02785c094ae6 | Capabilities | Take Screenshot | Delete Session | Load Script
Mac OS X 10.15.7 | v3.141.59 | re82be7d358
--> contains "Fragrant".
Scenario Steps:
2. $I->see("Fragrant") at tests/acceptance/QuizCest.php:14
1. $I->amOnPage("/") at tests/acceptance/QuizCest.php:13
Artifacts:
Png: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.png
Html: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.html
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
My Config file:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost:4444/wd/hub'
browser: chrome
- \Helper\Acceptance
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
step_decorators: ~
This excellent explanatory guide on how Selenium works led to a breakthrough.
I mistakenly thought the url for the WebDriver was the Selenium server url, but it was actually my MAMP url.
So I changed the port in my code to my MAMP url:
- WebDriver:
url: 'http://localhost:8888/wd/hub'
browser: chrome
- \Helper\Acceptance
And voila, a day of work finally complete. Hallelujah! Hope this helps someone else out.

Laravel : phpunit cannot open file ExampleTest.php

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

PHPUnit cannot open file

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.

PHP / Composer cannot redeclare

I was happily working away in my development environment and suddenly I started getting the following error:
PHP Fatal error: Cannot redeclare composerRequire7a368ac394ae1d2e857becf2a235ebaa() (previously declared in [APP_ROOT]/vendor/composer/autoload_real.php:56) in [APP_ROOT]/vendor/composer/autoload_real.php on line 59
I haven't made any changes to speak of in composer dependencies (although I think I did do a composer update somewhere in that timeframe but no changes to the dependencies/packages used so nothing big should have changed.
Notably, when I checkout the repo on my laptop I do NOT get this error but if I git clone a clean repo and then composer install on my main development machine I DO get this error. So I'm assuming it must have some machine-specific origin but I'm running out of ideas on what that might be.
Any help would be greatly appreciated.
Note: I'm running PHP 5.3.28 on OSX; my app uses namespacing and is PSR0 compliant
Also of note is that I'm running PHPUnit 4.0.17 and the error is triggered at the very first stages of trying to run a unit test (it doesn't matter WHICH unit test). Here's the stack trace:
0.0009 636648 1. {main}() [APP_BASE]/vendor/phpunit/phpunit/phpunit:0
0.0465 1423664 2. PHPUnit_TextUI_Command::main() [APP_BASE]/vendor/phpunit/phpunit/phpunit:54
0.0465 1424280 3. PHPUnit_TextUI_Command->run() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:132
0.0465 1424280 4. PHPUnit_TextUI_Command->handleArguments() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:141
0.0674 2123344 5. PHPUnit_TextUI_Command->handleBootstrap() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:638
0.0681 2139872 6. PHPUnit_Util_Fileloader::checkAndLoad() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:808
0.0681 2140008 7. PHPUnit_Util_Fileloader::load() [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
0.0774 2144176 8. include_once('[APP_BASE]/tests/test-loader.php') [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:93
0.0775 2146736 9. include('[APP_BASE]/vendor/autoload.php') [APP_BASE]/tests/test-loader.php:2
Delete composer.lock and vendor/ and run composer update again.
I had this problem when I made a copy of an existing project directory and tried to run phpunit on the new directory. Finally figured out that when I executed phpunit, it was running out of the old directory. I ran this:
which phpunit
And saw that it was running from my composer vendor directory:
/home/vagrant/Code/MYOLDPROJECT/api/vendor/bin/phpunit
I ran phpunit from the new directory and the problem disappeared:
/home/vagrant/Code/mynewproject/api/vendor/bin/phpunit

How to create PHP-UnitTest case for PHP_Codesniffer standards?`

I have created my own codesniffer rules standards.They are working fine. Now I want to test codesniffer rules using PHP UnitTest. PhpCodesniffer has already have their framework for PHPUnit test case.
So using that I have extended their AbstractSniffUnitTest and unit test class at location
Standards/TestRules/Tests/Function/FunctionUnitTest.php and script on which is to be tested kept in Standards/TestRules/Tests/Function/FunctionUnitTest.inc.
But when I am going to run the script by command phpunit PEAR\PHP\tests\AllTests.php, it gives following error.
PHPUnit 3.5.14 by Sebastian Bergmann.
......................................F
Time: 6 seconds, Memory: 10.00Mb
There was 1 failure:
1) TestRules_Tests_Function_FunctionUnitTest::getErrorList
An unexpected exception has been caught: Source file C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc does not exist
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php:138
C:\Program Files\PHP\PEAR\PHP\tests\TestSuite.php:48
FAILURES!
Tests: 39, Assertions: 146, Failures: 1.
Warning: Deprecated PHPUnit features are being used 2 times!
Use --verbose for more information.
It gives error file FunctionUnitTest.inc not found at given location. I have given full permission to folder also verify the path and file location, but it gives same error. I have tested it on linux machine also, but it gives same error.
Is it a my code issue or codesniffer unittest framework issue?
Are your files in the top-level tests or CodeSniffer directory? Note that the abstract test case you're extending is in tests
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php
but is trying to include the file from CodeSniffer:
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc
Try moving your two files to the other directory.
I see a space near i i nc - make sure if that is mis-typo and correct it, it should work. Other than this I don't see any problem.
Change:
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.i nc
To
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc
It seems that it has path issue on windows. I tested the test cases on Linux, it works fine. When I checked the actual code, it seems that on there is file mapping from test case file to sniff file. But on window, after file being mapped , the file path contains mixing of forward & backward slahes.But codesniffer not going to allow this. Because of that it is returning that “file is not found error”. Test cases are executing fine on Linux.

Categories