Why does running phpunit not run vendor/bin/phpunit? - laravel

I am having a weird issue,
when I run
$ phpunit
I get
Fatal error: Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php on line 185
Call Stack:
0.0009 231392 1. {main}() /home/vagrant/.composer/vendor/phpunit/phpunit/phpunit:0
0.0065 743872 2. PHPUnit_TextUI_Command::main() /home/vagrant/.composer/vendor/phpunit/phpunit/phpunit:47
0.0066 744512 3. PHPUnit_TextUI_Command->run() /home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:106
1.1720 6818904 4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:155
1.4597 16188088 5. PHPUnit_TextUI_ResultPrinter->printResult() /vagrant/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:446
However, when I run
$ ./vendor/bin/phpunit
it works as expected and runs my tests.
Maybe I have another program or something that is using the phpunit alias or something?
How can I debug to find that out?
Any ideas?

Assume you had installed phpunit from composer.json of current Laravel App.
Run this:
vendor/phpunit/phpunit/phpunit
Because the global one might be incompatible version of phpunit. Which is called and execute in the current package.

On windows I have an incompatible version installed globally.
To workaround, create "phpunit.bat" in root of project with contents:
"vendor/bin/phpunit"
This takes precendece over the phpunit in the system path.

How did you configure adding /vendor/bin to path?
I have this in my ~/.bashrc file:
PATH="$PATH:/path/to/vendor/bin"
This adds /vendor/bin/ to the end of your path, so if there is any other executable called phpunit earlier in your path - in your case, the globally installed one - it will be called instead.
To fix this, add vendor/bin to the beginning of your path in ~/.bashrc:
PATH="/path/to/vendor/bin:$PATH"
Then log out and log in or run source ~/.bashrc, and the system should then find /vendor/bin/phpunit first when you runphpunit.

On Windows, you can set an enviroment variable in your project's root directory.
Type this in your console/terminal:
set phpunit=vendor/bin/phpunit
I had the same problem with Laravel and PhpStorm, and after i typed this in my PhpStorm terminal, the problem was solved.

I've just found about about doskeys for Windows. I think they are called aliases on Mac, but they allow you to create a command as an alias for another command.
This way, I can use:
doskey macroName=macroDefinition
which in my case is:
doskey p=.\vendor\bin\phpunit
which then means I can just use the command p from my project folder for phpunit - much quicker!
For example I can now use the command:
p --filter my_single_test tests/MyExampleTest.php

Related

go-swagger restapi/configure_todo_list.go - api.TodoGetHandler undefined error

I am a newbie in go and go-swagger. I am following steps in Simple Server tutorial in goswagger.io.
I am using Ubuntu 18.04, swagger v0.25.0 and go 1.15.6.
Following the same steps, there are a few differences of the files generated. For instance, goswagger.io's has find_todos_okbody.go and get_okbody.go in models but mine does not. Why is that so?
Link to screenshot of my generated files vs
Link to screenshot of generated files by swagger.io
Starting the server as written in the tutorial go install ./cmd/todo-list-server/ gives me the following error. Can anyone please help with this?
# my_folder/swagger-todo-list/restapi
restapi/configure_todo_list.go:41:8: api.TodosGetHandler undefined (type *operations.TodoListAPI has no field or method TodosGetHandler)
restapi/configure_todo_list.go:42:6: api.TodosGetHandler undefined (type *operations.TodoListAPI has no field or method TodosGetHandler)
The first step in goswagger.io todo-list is swagger init spec .... Which directory should I run this command in? I ran it in a newly created folder in my home directory. However, from the page, it shows the path to be ~/go/src/github.com/go-swagger/go-swagger/examples/tutorials/todo-list. I am not sure whether I should use go get ..., git clone ... or create those folders. Can someone advise me?
Thanks.
This is likely the documentation lagging behind the version of the code that you are running. As long as it compiles, the specific files the tool generates isn't so crucial.
This is a compilation error. When you do go install foo it will try to build the foo package as an executable and then move that to your GOPATH/bin directory. It seems that the generated code in restapi/configure_todo_list.go isn't correct for the operations code generated.
All you need to run this tutorial yourself is an empty directory and the swagger tool (not its source code). You run the commands from the root of this empty project. In order not to run into GOPATH problems I would initialise a module with go mod init todo-list-example before doing anything else.
Note that while the todo-list example code exists inside the go-swagger source, it's there just for documenting example usage and output.
What I would advice for #2 is to make sure you're using a properly released version of go-swagger, rather than installing from the latest commit (which happens when you just do a go get), as I have found that to be occasionally unstable.
Next, re-generate the entire server, but make sure you also regenerate restapi/configure_todo_list.go by passing --regenerate-configureapi to your swagger generate call. This file isn't always refreshed because you're meant to modify it to configure your app, and if you changed versions of the tool it may be different and incompatible.
If after that you still get the compilation error, it may be worth submitting a bug report at https://github.com/go-swagger/go-swagger/issues.
Thanks #EzequielMuns. The errors in #2 went away after I ran go get - u -f ./... as stated in
...
For this generation to compile you need to have some packages in your GOPATH:
* github.com/go-openapi/runtime
* github.com/jessevdk/go-flags
You can get these now with: go get -u -f ./...
I think it's an error of swagger code generation. You can do as folloing to fix this:
delete file configure_todo_list.go;
regenerate code.
# swagger generate server -A todo-list -f ./swagger.yml
Then, you can run command go install ./cmd/todo-list-server/, it will succeed.

Launch ClojureScript + ghost script from terminal

I installed phantomjs and casperjs, created a new project with lein new mies casper-ghost and added the [ghost "0.1.0-alpha1] dependency to project.clj.
I then copied over the example code from https://github.com/casperjs/ghost to the core.cljs file and successfully compiled it, with ./scripts/build.
When I try to run it with casperjs out/casper_ghost.js it gives me the error:
ClojureScript could not load :main, did you forget to specify :asset-path?
ReferenceError: Can't find variable: goog
file:///usr/lib/node_modules/casperjs/bin/bootstrap.js:1 in global code
I tried creating a custom build script as follows:
(require 'cljs.build.api)
(cljs.build.api/build "src"
{:main 'hello-world.core
:output-to "out/main.js"})
And ran that successfully with lein -m clojure.main build.clj, but running out/main.js with casperjs would cause the same error.
Can someone point me in the right direction how to run the ghost scripts from the linux terminal?
Making the Google closure compiler write everything into a single file by using :optimizations "simple" to the build options did the trick.

PHPUnit needs an absolute path to phpunit.xml

I am trying to use phpunit through the CLI in order to migrate from Netbeans to Sublime Text.
I have the weirdest issue when giving phpunit the path to the phpunit.xml file : it only accepts absolute path et refuses any relative path.
Any relative path given to the phpunit.xml file leads to this error :
Could not read "phpunit.xml"
Example :
Maximes-MacBook-Pro:Frontoffice mbritto$ pwd
/Users/mbritto/Documents/Frontoffice
Maximes-MacBook-Pro:Frontoffice mbritto$ phpunit -c phpunit.xml
Could not read "phpunit.xml".
The phpunit.xml is present in this folder and is readable by my user.
It actually works if I don't give the path to the file :
Maximes-MacBook-Pro:Frontoffice mbritto$ phpunit
PHPUnit 3.7.28 by Sebastian Bergmann.
Configuration read from /Users/mbritto/Documents/Frontoffice/phpunit.xml
#Preparing Application Unit Tests
.^C
Or if I give the absolute path to the file :
Maximes-MacBook-Pro:Frontoffice mbritto$ phpunit -c /Users/mbritto/Documents/Frontoffice/phpunit.xml
PHPUnit 3.7.28 by Sebastian Bergmann.
Configuration read from /Users/mbritto/Documents/Frontoffice/phpunit.xml
#Preparing Application Unit Tests
..^C
I need this in order to use the phpunit plugin in Sublime Text which gives the phpunit.xml file to the command line with the path to the file to test.
My config :
OSX 10.9.1
PHP 5.4.24 (via brew)
PHPUnit 3.7.28 (via brew) (also tested with a phar)
Any idea why it would do that ?
I finally found out what was wrong with my tests; in my bootstrap.php file I was doing this :
chdir(dirname(__FILE__) . "/../src/");
So that classes and autoload would find actual classes that are separated from my test classes.
If I remove this line, the tests crashes because it can't find my classes but at least my tests are executed.
I'll work on the include path rather than changing directory so my tests will be working again.

Coffeescript/cake on Windows: Cakefile can't be found

I have a ~\Cakefile that looks like this:
task 'say:hello', 'Howdy!', (options) ->
console.log 'Hello, world!'
But running cake (which resolves to C:\Users\bstraub\AppData\Roaming\npm\cake.cmd since it was installed with npm) gives this error:
Error: Cakefile not found in C:\Users\bstraub
The file exists. What am I doing wrong?
path.exists and path.existsSync were broken for Windows in node 0.6.9. Updating to 0.6.13 corrects this, and cake works.
Check if the file is really called Cakefile and not CakeFile or something.
Check if ~\Cakefile maps to C:\Users\bstraub\Cakefile.
The ~ might map to some other dir, depending on your system config
(e.g., with cygwin, git-bash, or a funny corporate env var setup).
Check if cd ~ really brings you to C:\Users\bstraub

Path Error running CakePHP's "cake" console utility in Windows

A while ago when I started with Cake, I managed to get the console running in my Windows environment, and I have no idea how. I'm now having problems to make it work again in another computer.
This is what I've done in the new machine:
Downloaded my Cake code from source control (so all the files are exactly the same as the computer where it worked, including the configuration files)
Added PHP and "c:\my_cake_path\cake\console" to the path
If I run "cake OneOfMyShells", either standing on the /app, or in /cake/console directories, I get the following error:
Warning: get_object_vars() expects parameter 1 to be object, null given in C:\my_cake_path\cake\libs\model\connection_manager.php on line 199
Error: Missing Database Connection. Try 'cake bake'
"cake Bake", if run normally, when I try to get it to do the DB config ends up throwing another error (which is not that relevant to this)
However, if I run: cake bake -app "c:\my_cake_path\app"
Then bake works, I can do the database config, and it writes the DB config file (which is useless at this point, since I already had one)
Then, of course: cake OneOfMyShells -app "c:\my_cake_path\app"
does work perfectly well.
So, everything's working fine, I just need to manually specify the path to "app" every single time, which is very annoying.
How can I get around this? Where is Cake looking for to find the path to app?
Thanks!
Daniel
Not much of a difference in the sense you still need to type but you can run cake from the app dir like this: C:\XXX\project\app> ..\cake\console\cake.bat
To make it smaller you can put that line on a .bat or just add the \cake\console dir the windows path

Resources