How to deal with unit-tests in Zend Framework 2? - unit-testing

I have a Zend-Framework 2 Project and i have problems to organize my unit-tests. My unit-test are located in one "test"-folder for each module. If I run the test from the command line with phpunit in the test folder of a module, the test will run successfully.
Example:
c:\project\module\AccessControl\test>phpunit
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from c:\project\module\AccessControl\test\phpunit.xml
........Time: 0 seconds, Memory: 8.25Mb
OK (8 tests, 10 assertions)
Problem: Here only one module will be testet. But I want to run a single testsuite from the folder c:\project\ to test the hole project.
There I have put a bootstrap.php and a phpunit.xml.
From the command line I run it with:
C:\project\tests>phpunit --debug --configuration phpunit.xml
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from C:\project\tests\phpunit.xml
Starting test 'AccessControlTest\Model\AuthenticationTest::testInitDefault'.
PHP Fatal error: Class 'AccessControlTest\Bootstrap' not found in C:\project\module\AccessControl\test\AccessControlTest\Model\AuthenticationTest.php on line 22
PHP Stack trace:
PHP 1. {main}() C:\Program Files (x86)\PHP\phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() C:\Program Files (x86)\PHP\phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\Command.php:129
PHP 4. PHPUnit_TextUI_TestRunner->doRun() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\Command.php:176
PHP 5. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\TestRunner.php:346
PHP 6. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:705
PHP 7. PHPUnit_Framework_TestSuite->runTest() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:745
PHP 8. PHPUnit_Framework_TestCase->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:775
PHP 9. PHPUnit_Framework_TestResult->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestCase.php:769
PHP 10. PHPUnit_Framework_TestCase->runBare() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestResult.php:648
PHP 11. AccessControlTest\Model\AuthenticationTest->setUp() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestCase.php:821
The file phpunit.xml looks like this:
<phpunit bootstrap="./Bootstrap.php" colors="true" verbose="true">
<testsuite name="SgtrCatalogTestsuite">
<directory>../module/AccessControl</directory>
</testsuite>
</phpunit>
It looks like some modulepaths are not correct. Can somebody help and tell me how to setup this?
EDIT
Ty for your replys!!!
In the meantime i found this:
How to consolidate ZF2 unit/application module tests into a single call?
It seems not possible to run all module-tests from rootlevel. I try now to use this and let u know if it works: https://github.com/prolic/HumusPHPUnitModule

Try adding this section in your composer.json
"autoload": {
"psr-0": {
"AccessControlTest\\": "tests/",
"AccessControl\\": "src/module/AccessControl/src/"
}
}
And then run
$ php composer.phar dump-autoload

Related

Docker image for building solution with both C++ and C# projects

I had a docker file that used to successfully build a VS2019 solution containing C++ and C# projects. Then recently it stopped working.
I've been investigating and trying various combinations of docker images, without success.
I've now got a test VS2019 solution with one C++ hello world console project and one C# .NET5 hello world console project. This does not compile using the following docker file:
e# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
SHELL ["cmd", "/S", "/C"]
# Copy our Install script.
COPY Install.cmd C:\TEMP\
# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\Temp\vs_buildtools.exe
ADD https://aka.ms/vs/16/release/channel C:\Temp\VisualStudio.chman
RUN C:\Temp\vs_buildtools.exe `
--quiet --wait --norestart --nocache `
--installPath C:\BuildTools `
--channelUri C:\Temp\VisualStudio.chman `
--installChannelUri C:\Temp\VisualStudio.chman `
--add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
--add Microsoft.Component.MSBuild `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
WORKDIR /src
ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] && CMD "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Commom7\Tools\VsDevCmd.bat"
The compiler error is
C:\src\dockertest\ConsoleApplications\ConsoleApplicationCpp\ConsoleApplicationCpp.vcxproj(28,3): error MSB4019: The imp
orted project "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.D
efault.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Vi
sual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props" is correct, and that the file exist
s on disk.
Interestingly, this installs MSBuild for VS2022, despite the aka.ms/vs/16 link requesting VS2019.
Interestingly, this installs .NET SDK 6.0.101, despite the FROM line asking for 4.8
But the main problem is the VC tools are not installed. The folder C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft does not contain the VC folder.
I've followed various examples but they don't appear to work any more with the recent docker images.
Try this:
# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
SHELL ["cmd", "/S", "/C"]
ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\vs_buildtools.exe
RUN C:\vs_buildtools.exe `
--quiet --wait --norestart --nocache modify `
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
--add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools;includeRecommended `
--add Microsoft.VisualStudio.Workload.MSBuildTools;includeRecommended `
--add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN del C:\vs_buildtools.exe
COPY . .
RUN nuget restore
RUN MSBuild GameClient.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64
WORKDIR /Product
ENTRYPOINT ["C:\\Product\\WOTS.exe", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

wrong version of expo-cli after upgrade

for many time i get the following info message after start expo projects, and it seems its not possible to upgrade expo-cli:
There is a new version of expo-cli available (4.2.1). You are currently using expo-cli 3.28.0 Install expo-cli globally using the package manager of your choice; for example: npm install -g expo-cli to get the latest version
This seems easier as it looks. After installing expo-cli globally without errors
+ expo-cli#4.2.1
OK, now im typing expo -V to check the new Version but wait: its 3.28.0
My project package.json dont have expo-cli in. Is there a way to locate the used expo version?
edit:
i found 1 PATH file till now.
(C:\Users\myuser.expo) it contents:
C:\Users\SYSTEM~1\AppData\Local\Temp\yarn--1615049876273-0.687029522126771;
C:\Users\myuser\WfManager\fmapp\node_modules\.bin;
C:\Users\myuser\AppData\Local\Yarn\Data\link\node_modules\.bin;
C:\Program Files\libexec\lib\node_modules\npm\bin\node-gyp-bin;
C:\Program Files\lib\node_modules\npm\bin\node-gyp-bin;
C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;
C:\Program Files (x86)\Lenovo\FusionEngine;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;
C:\Program Files (x86)\Common Files\Apple\Apple Application Support;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\System32\OpenSSH\;
C:\xampp\php;
C:\Program Files\Git\cmd;
C:\Program Files\PuTTY\;
C:\Program Files\Symfony;
C:\Program Files (x86)\Yarn\bin\;
C:\Program Files\nodejs\;
C:\composer;
C:\Users\myuser\AppData\Local\Microsoft\WindowsApps;
C:\Users\myuser\AppData\Local\Programs\Microsoft VS Code\bin;
C:\Users\myuser\AppData\Roaming\Composer\vendor\bin;
C:\Users\myuser\AppData\Local\Yarn\bin;
C:\Users\myuser\AppData\Local\GitHubDesktop\bin;
C:\Users\myuser\AppData\Roaming\npm
after writing this down and check the entries i found one entry which
links to an old version:
C:\Users\myuser\AppData\Local\Yarn\Data\link\node_modules\.bin; //old version
C:\Users\myuser\AppData\Roaming\npm //new version`
i want to update expo-cli with xarn global now and we will see what happens.
You can check path to binary with command -v expo.
In this case you most likely installed expo-cli globally both with npm and yarn, version 3.28.0 is just earlier in your PATH. It's also possible that you have two node versions (and 2 npm versions) installed, but it's less likely.

getting this error: unrecognized option --skeleton-test using PHPUnit 3.7.10 using Netbeans 7.1.2

I have installed PHPUnit via pear installer - but I'm having trouble getting it to work get this error when using Tools> Create PHPUnit Tests
The output error is: PHPUnit 3.7.10 by Sebastian Bergmann. unrecognized option --skeleton-test
This is the Unit Testing tab in Netbeans:
Tried different include paths in the General Tab but not sure how to include the classes
Any ideas what is wrong...? thanks
Verify that the phpunit-skelgen file exists in the same directory as the phpunit binary (C:\wamp\bin\php\php5.3.5\ in your installation).
If not, install the PHPUnit SkeletonGenerator the same way you installed PHPUnit, eg from PEAR:
C:\wamp\bin\pear.exe install phpunit/PHPUnit_SkeletonGenerator

netbeans cakephp unittest PHP Fatal error: Class 'App' not found in {filename} line 3

I am trying to run unit test from netbeans but it fails with this error.
PHP Fatal error: Class 'App' not found in /home/user/cakephp/app/Test/Case/Model/AceScoreTest.php on line 3
Stack trace:
1. {main}() /usr/bin/phpunit:0
2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
5. ReflectionMethod->invoke() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:124
6. NetBeansSuite::suite() /usr/local/netbeans-7.2.1/php/phpunit/NetBeansSuite.php:0
Unit test works fine when run from the command line as
./cake test app Model/AceScore
What do I need to do to get cakephp unit test to work in Netbeans?
There must be some way to tell phpunit to look for App.php in lib/Cake/Core/App.php
Thanks.
Perhaps, you have to create a bootstrap file for PHPUnit and set it to NetBeans.
I have added new Action (PHPUnit Test Init Action[1]) to CakePHP pluign for NetBeans[2].
If you are using this plugin, please try it ;) Please see [1] about bootstrap file.
[1] https://github.com/junichi11/cakephp-netbeans#phpunit-test-settings-phpunit-test-init-action
[2] http://plugins.netbeans.org/plugin/44579/php-cakephp-framework

PHPUnit + Symfony does nothing

I just installed PHPUnit on OS X + MAMP. (My phpunit was installed in my MAMP folder, so I copied it to /usr/bin because I couldn't use the "phpunit" command in terminal without the path)
New Symfony folder
When I go to a new Symfony2 folder and I try phpunit -c App/the tests start and I get a green confirmation that all tests passed.
PHPUnit 3.7.8 by Sebastian Bergmann.
Configuration read from
/Users/username/Dropbox/www/symfonydev/Symfony/App/phpunit.xml.dist
.
Time: 0 seconds, Memory: 15.50Mb
OK (1 test, 1 assertion)
Own symfony website
But when I go to my own little Symfony2 project and execute the same command, nothing happens! He doesn't even load the phpunit.xml.dist. I get no output at all on my terminal window.
The test file, however, does exist and is readable, I can start it by explicitly specifying it on the command line of phpunit:
phpunit -c app/ src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.phpand this works.
It seems that something is wrong with the phpunit.xml.dist. It's the default phpunit.xml.dist and I tried renaming it to phpunit.xml. But nothing happens. What could be the problem? I think he can't find my xml or use it, or maybe he can read the phpunit.xml but doesn't find my tests.
Here's an example from my terminal: You see that the phpunit command doesn't do anything, except when I specify the test file...
MacBook-Pro:www username$ ls
LICENSE app composer.json composer.lock composer.phar src vendor web
MacBook-Pro:www username$ ls app/
AppCache.php SymfonyRequirements.php cache console phpunit.xml.dist
AppKernel.php autoload.php check.php logs
Resources bootstrap.php.cache config phpunit.xml
MacBook-Pro:www username$ phpunit -c app/
MacBook-Pro:www username$ phpunit -c app/ src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.php
PHPUnit 3.7.8 by Sebastian Bergmann.
Configuration read from /Users/username/Dropbox/www/matchtracker.be/www/app/phpunit.xml
F
Time: 1 second, Memory: 21.75Mb
There was 1 failure:
1) MatchTracker\Bundle\Tests\Controller\DefaultControllerTest::testIndex
Failed asserting that 404 matches expected 200.
/Users/username/Dropbox/www/matchtracker.be/www/src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.php:28
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
MacBook-Pro:www username$
What's in your phpunit.xml? <testsuites> section of this file tells phpunit which directories scan for tests.
Remember that phpunit.xml overwrites phpunit.xml.dist.
Look at the original phpunit.xml.dist file and either remove the phpunit.xml or start by copying phpunit.xml.dist into phpunit.xml.