Summer Sale! All accounts are 50% off this week.

laracoft's avatar

Testing a standalone script

#!/bin/sh
<?php
...

I have a PHP script that handles piped email, it doesn't have autoload etc in order to speed things up. Any idea how I can test the code inside using Laravel and PHPUnit? Thank you.

0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Maybe a unit test where you manually include that file and call its methods (if there are any?)

laracoft's avatar

@Sinnbeck

The part about require_once is a good one, but the script needs to be "deactivated" first during tests, similar to calling Http::fake(), otherwise actual code will run.

I'm using this to determine if we are under tests

if (defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__')) {
    // PHPUnit is running
    return;
}

I also refined the problem further, it's more to do with how can we test cURL

https://stackoverflow.com/a/7912399/3872647

Please or to participate in this conversation.