theProfit's avatar

Artisan Test if failed mail me

Hi all,

Is there a way to let my tests run every hour on failure mail me? Now if i do php artisan test i can see the response if all my tests passed. i can code it in every test line but this is to much work.

0 likes
14 replies
theProfit's avatar

It is more like a self test so i have a lot of test scripts made by php artisan make:test now i want to run periodic or before deploy and after deploy php artisan test to check hunderd of scripts if php artisan test fails i want ot have a email.

theProfit's avatar

So what i want:

  1. Run php artisan test
  2. if all mark green do nothing else email me.

This so i can run php artisan test as many times i want.

martinbean's avatar

Is there a way to let my tests run every hour on failure mail me?

@theprofit Why?

i have a lot of test scripts made by php artisan make:test now i want to run… before deploy

Do this. Run your tests before deploying your code. This is called continuous integration. You push some code to a build server, it builds and runs your application’s tests, and in any fail then the deployment is cancelled. This ensures only code that passes your tests reaches a production server.

There’s no point running tests periodically because code may not have changed in that timeframe, or may have changed multiple times where you haven’t tested each change, so if a test did fail you’d then have many commits to go through to work out where the bug was introduced.

So again, run your tests on deployment. If one deployment succeeds but then the next fails, you know exactly which commit to look in for the bug that’s causing your tests to fail.

2 likes
theProfit's avatar

Why because a application can have connections to other vendors they can also break. therefore a application always must be testable on every function or connection. now it is done by hand to run php artisan test wait 20 minutes and fire like 100+ tests.

you can write a code on every function if it fails fire a email but i want test everything if it all is green great if not mail me.

theProfit's avatar

the above do this evert hour is not correct i know but to let you know i want to do it periodic, like we can test the hole application and connected applications when we need to like once a month or so.

The point and question is is there a way to mail when php artisan test fails?

ItsClassified's avatar

@theprofit The php artisan test tests that u make should only be run on the build just as @martinbean said.

Im pretty sure if u try to run 'php artisan test' on production it will tell you that test does not exists since its not installed when you do 'composer install --no-dev'.

If u want to test the connections to your databases or to another application/api you could create a Job that does that and fire it every hour. Then if it can't connect it could send you an email.

https://laravel.com/docs/8.x/scheduling

Also running actual tests on production is just scarry! If you mess up a config or a setting your whiping you whole database. I'd recommend not doing that :PP

1 like
theProfit's avatar

I think there is confusion, a very simple question I am doing a test how can I get the status of this?

this is not about production testing, but about testing whether a supplier still responds to its api, for example.

Apart from this a very simple question I ask:

vendor/bin/phpunit or php artisan test

how can i make sure that if this failed i want an email.

is this possible? let's skip the whole discussion about why.

martinbean's avatar

@theprofit You have a build server that runs your tests, and has some sort of hook that sends an email if phpunit returns a non-zero exit code (i.e. it failed).

But if you’re testing vendor connections then these shouldn’t be PHPUnit-based tests. You‘re not testing your code; you‘re testing a third party.

theProfit's avatar

Yes agreed only sometimes you have to deal with old unstable parties. So therefore the checkups normaly you dont need it but with some parties you should.. But thanks for the reply

martinbean's avatar

@theprofit PHPUnit is for testing your application, though. What you’re describing is an integration test, where you’re checking how a third-party is operating, so shouldn’t be in PHPUnit tests at all.

1 like
theProfit's avatar

Thanks @martinbean what would you advise in this if a test leans on code from a other party. This party has a high downtime on api's (SOAP) or faulty responses.

Snapey's avatar

Then the testing of availability of the third party API should be part of your application that you run from a scheduled task.

Please or to participate in this conversation.