Dusk issue
running Vagrant box with custom url on my mac. I had to edit DuskTestCase.php and replace http://localhost:9515 with $this->local = http://mysite.dev.
$php artisan dusk tests/Browser/LoginTest.php outputs following error:
Tests\Browser\LoginTest::testLogin
TypeError: Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in /Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php on line 127
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/DesiredCapabilities.php:33
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:127
/Users/gmylonas/Vagrant Projects/mywebsite/tests/DuskTestCase.php:46
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:210
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/framework/src/Illuminate/Support/helpers.php:762
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:211
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:117
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:89
/Users/gmylonas/Vagrant Projects/mywebsite/tests/Browser/LoginTest.php:23
When I replace $this->local = http://www.google.com:80 and $browser->visit('/')->dump(); it dumps the content of google page!
$this->local = http://localhost:9515 will dump empty page
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>
:question: Why it won’t work on my box url and how to solve it?
Thanks is advance.
The thing is that you shouldn't update http://localhost:9515 to anything else. This is selenium driver and by default it's using this port and it should work without any problem.
By default when running:
$browser->visit('/')
it should visit the main url of your page without any other changes. However depending on your application you might need to set APP_URL in your .env file especially when your application makes some domain checks.
Related
Is it possible to get $output as follows:
$output = Artisan::call('command:name');
I have tried many solutions in different posts but it didn't work on my Laravel 5.2.
You can call the output method on Artisan
Artisan::call('command:name');
$output = Artisan::output();
Make sure you are using one of the available output methods like $this->line('output'); in the actual Artisan command. More info in the docs.
There are several ways to accomplish this, but as your are using such old version of Laravel maybe the best for your case is one that will not require a rewrite when you finally migrate to a newer version. Have you tried perhaps the vanilla PHP methods system, shell_exec and passthru?
system will return just the last line of the command on succes and FALSE on failure
shell_exec will return the entire output but without a way to fetch the output status code
passthru will not return any output instead it will output all on stdout. Although it can be put into a variable using output cache methods (i.e. ob_start and ob_get_contents)
In any case you should call those methods using as argument the CLI version of the command you wish to run:
$output = shell_exec("php artisan command:here");
P.S. If you by any chance have a user input that you want to pass as parameter to a artisan command, make sure you escape it with escapeshellcmd first.
Right now in Capistrano I have it doing
execute "echo #{fetch(:stage)}"
Which echoes out "staging"
On the very next line I have
if fetch(:stage) == "staging"
Which never equals true. I tried changing it to if "staging == "staging" and it enters the body of it. Uh, what gives and how do I do a check to only run one line of code for staging.
fetch(:stage) is likely a symbol (it's been a while since I used capistrano). To verify this, use a more precise string representation:
execute "echo #{fetch(:stage).inspect}"
I'm betting it will print :staging. In which case you need to do
if fetch(:stage) == :staging
First of all let's start saying I am running the whole project in a Docker container and that means I don't have anything installed on the host.
Having that I am trying to debug a Symfony command which is kind of CLI script with the difference it's not being called as php script.php but as bin/console command.
What does the console file has inside it? See below:
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
set_time_limit(0);
/** #var Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
I have Xdebug installed and configured, I have phpStorm configured as well and that means using the browser (and the extension to enable/disable) I can debug whatever I want.
Typically this is how the command is executed from the console (bash):
<path_to_symfony>/bin/console quote:notify -d 120 -e <some_email>
Options are optional here and that means I can call the same as:
<path_to_symfony>/bin/console quote:notify
It will work both ways. I am using the docs from here to debug such command. Now this is how I am setting up the IDE to debug a Symfony command:
Go to Run/Debug Configuration
Click on Add button (little green + symbol)
Choose PHP Script
Name it as SF Command
At File box I wrote bin/console
At Arguments box I wrote quote:notify (which is my command)
But the IDE says first: Error: file not specified or invalid and then when I try to execute the command it says it's not a valid configuration. (also notice the little "X" which should means something is wrong)
What I am missing here? Can I get some help here? I am using the latest version of phpStorm.
I'm trying to run an Artisan command with an argument, but I can't figure out how. How do you do it? If I run php artisan video:webmtomp4 N in the terminal, it works fine.
Artisan::call(
'video:webmtomp4',
[$data['videoId']],
new StreamOutput(fopen(storage_path() . '/logs/artisan.log', 'w'))
);
How do you send an argument to the command when using Artisan::call? $data['videoId'] is set, so that is not a problem.
Changing my comment to an answer after checking the documentation. :)
The parameters array should be associative, e.g. ['argument' => $data['videoId']],.
I'm creating a custom artisan command (foo) for my Laravel 4 application. I can see from the userguide how to accept arguments and options, e.g.
php artisan foo argument --option
But what if I want to have a custom artisan command that has many 'methods', in the same style as some built-in artisan commands, e.g. migrate:install?. I want to make something like:
php artisan foo:baz argument --option
What is the recommended way to implement different methods based on the : colon separator? All I've found to try so far is to make an entirely new artisan command for each 'method'. Is there a more efficient way?
You're correct, you do need a new Artisan command (or rather a class) for each method. However all you have to do is register each file in app/Console/Kernel.php, if you decide to change the syntax later than Laravel will pick it up any changes to $signature automatically without you needing to rename any files.
For the Laravel example you mention, migrate, there's a directory with a separate file for each command name (including the one that has no colon):
/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations
migrate -> MigrateCommand.php
migrate:install -> InstallCommand.php
migrate:refresh -> RefreshCommand.php
migrate:reset -> ResetCommand.php
migrate:rollback -> RollbackCommand.php
migrate:status -> StatusCommand.php
If you have code you want to reuse (DRY) note that if you examine the above commands, some of them use traits, e.g. Illuminate\Console\ConfirmableTrait – which contains a confirmToProceed() method which, if it's running in production, will ask the user if they really want to continue.
NB: the Artisan syntax changed in 5.1, from $name (with a rather complicated way of specifying arguments and options) to the much simpler $signature, it's backwards compatible. More info
You just have to set the name:
protected $name = 'foo:baz';