I need to make a tool to Browser test my production system. I have read up all about Laravel Dusk and it seems like a perfect tool. However, I need to run tests automatically via schedule and have a dashboard with the results.
I can easily run the command php artisan dusk from the code using the Scheduler, however, how can I get the results? Is there a better option than simply parsing the Console Output from that command? Ideally I would have a way of getting the status of each test (whether it passed or failed) to be able to log, process and display all that information.
The Dusk documentation hasn't got any more information on running the tests programatically, it only has instructions to run via php artisan dusk.
Has anyone encountered this?
Thank you!
The way I have achieved what I needed is to use the command options for dusk/phpunit.
I used --filter=MyTestClass to single out which test I wanted to run, and --log-junit log.log to log the results for that test, which I then parsed via code as well to fetch the results. This allowed me to build a fully custom dashboard that was able to run each test individually, report the results, send notifications etc.
Not the prettiest solution, but it worked well for what I needed. If anyone encounters better way to achieve that (or just use Dusk in general as a browser/scraper outside phpunit) please do post a comment/answer!
Related
I find the Symfony Console documentation to be quite good. In clear language, it explains how to use Symfony Console to write console commands in PHP, including how to take user input, how to render output, and even how to write tests for these console commands.
However, the documentation doesn't seem to explain how to run these tests. Assuming one has written a test like CreateUserCommandTest.php, which they provide as an example, how would they run it?
I am the sole person in charge of a website that keeps track of records that other employees submit and compiles them into nice spreadsheets so that non-technical users can easily read them.
The other guy who used to work here quit unexpectedly, and I have to make a small, one-line change to the PHP code that he wrote, the problem is, when I edit the code, it does not seem to change anything. For example, I can completely delete the code that displays an error message, but that error message will still show up. There are other parts of the project that I CAN modify, like XML files and python programs, but the PHP does not seem to care if it is modified.
I vaguely remember a command like 'php artisan serve' but that doesn't seem to help either
After googling the problem, I came across several other commands like 'npm run production' and 'php artisan optimise' but those didn't work either.
Thanks for your help
Are you changing the code directly on the server? Or are you trying it local first? Is the change on a view-file?
Try php artisan cache:clear. It should clear all the caches and probably show your changes.
I am currently creating an automated test website where all codeception test logs can be shown. My server runs codeception through cron but the user should be able to run the test manually. My question is can I use codeception class in a php webpage without executing the commandline version? If possible anyone have an idea how?
Yes you can, it is actually also quite simple. Codeception uses the symfony console component for their command line tool. Take a look at the \Codeception\Command\Run::execute() method on how they do it. It can be a bit overwhelming at first glance, but in the end it boils down to this piece of code:
$this->codecept = new Codecept($userOptions);
if ($suite and $test) {
$this->codecept->run($suite, $test);
}
I have a test suite for my cakephp web app using the cakephp phpunit wrapper provided in 2.x. I would love to merge my test suite into production and be able to test periodically in production via a test database. My issue is as followed:
CakePHP uses a file called test.php to run the test suite and index.php to run the site. I want to lock access to my test suite behind our administrative login, because I don't want anyone to be able to run my test suite on our site just by navigating to www.myapp.com/test.php
I cannot find any information about how to do this. Its possible that no one is doing this because this is a bad strategy that I have propose. If that is the case, could someone please direct me to a better cakephp testing strategy. Sorry, I'm new to building tests.
Thank you to anyone that can help.
Don't use the web test suite but use the command line instead. See "Running tests from the command line".
cake test
Also running tests on a production system might not be a good idea either as it can put some load on the server and the site might respond very slow while the tests run.
If you run the tests via command line you can use the command "nice" and set how much CPU load the command you're going to execute is allowed to cause.
Here we set up a server that we run right next to production called development. These two servers are exact matches (I hope...) and we run our test suite from there. I still run them through the browser, but I agree that the command line works as describe by #burzum. Testing on live is a bad idea. It could mess things up and is not worth the risk for us.
Can anyone tell me, how to access an action URL of symfony using terminal in ubuntu?
For Example:
http://mysymfonyproject.com/index.php/users/sendnewsletter
Same way, I want to set up an action class URL as cron job. Is it possible to set up cron jobs in symfony?
For Example:
http://mysymfonyproject.com/index.php/crons/sendnewsletter
I think a Symfony Task is what you should look into. There's a lot of built-in tasks, but you probably should write your own task and then call it from cli using a command:
php symfony yourTaskNamespace:yourTaskName
Then you can add such command as a regular cronjob task.
You can check detailed instruction how to create custom Symfony tasks at Documentation Page
Using tasks is the best solution (as Tomasz Madeyski suggested). Just be aware that the tasks work a bit differently than the web app (e.g. read about using sfContext in tasks)
You can also use curl to access your sf pages directly from CLI:
curl -sS http://mysymfonyproject.com/index.php/crons/sendnewsletter >> mylog.log
The -sS option will make curl silent unless there's an error. You can skip that if you don't need it.
The last part (>> mylog.log) will append the result of the request to the log file (it's best if you specify whole path to the log file)
As for setting the cron job it's fairly easy no matter if you use curl or sf tasks. Have a look around the web for a tutorial on setting the crontab, there's plenty of them out there.