mercredi 2 novembre 2016

test class is not specified or invalid

I need to run a couple of tests on a console command, each of which will have a small change to the database before the test is run. I've structured this as follows:

class ActionRemindCommandEmail extends KernelTestCase
{
    private $mailCollector;


    /**
     * @return mixed
     */
    public function getMailCollector()
    {
        return $this->mailCollector;
    }


    /**
     * @param mixed $mailCollector
     */
    public function setMailCollector($mailCollector)
    {
        $this->mailCollector = $mailCollector;
    }



    protected function setUp()
    {
        exec('mysql database < prep.sql');
    }


    public function testExecute()
    {
        exec('echo "' . str_replace('"', '\\"', $this->getPrepSql() ) . '" | mysql database');

        self::bootKernel();
        $application = new Application(self::$kernel);

        $application->add(new ActionRemindCommand());

        $client = static::createClient();
        $client->enableProfiler();
        $this->setMailCollector($client->getProfile()->getCollector('swiftmailer'));

        $command = $application->find('app:ahp:remind');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
                                    'command'  => $command->getName(),
                                    'email' => ''
                                ));
        $output = $commandTester->getDisplay();
        $this->assertions();
    }
}

and the first actual test looks like this

    class ActionRemindCommandVetNotifyWhenSavedOnlyTest extends ActionRemindCommandEmailTest
{

    protected function getPrepSql()
    {
        return "INSERT INTO `action` (farmer_id`, `group_id`, `name`, `due`, `active`, `completed`, `notify_vet_email`, `notify_farmer_email`, `notify_vet_text`, `notify_farmer_text`, `notify_tech_text`, `notify_clinic_email`, `notify_farmer_text2`, `notified_vet_email`, `notified_farmer_email`, `notified_clinic_email`, `notified_vet_text`, `notified_farmer_text`, `notified_farmer_text2`, `notified_tech_text`, `notify_vet_email_advance`, `notify_farmer_email_advance`, `notify_clinic_email_advance`, `notify_vet_text_advance`, `notify_farmer_text_advance`, `notify_farmer_text2_advance`, `notify_tech_text_advance`, `no_time`, `notes`, `pending_offline_id`) VALUES "
                . " (116, NULL, 'Action 1', '"
                    . date('Y-m-d H:i:s',mktime(12,0,0,intval(date('n')), intval(date('j'))+14,intval(date('Y'))))
                . "', 1, 0, 1, 0, 0, 0, 0, 0, 0, '000', '000', '000', '000', '000', '000', '000', -1, -1, -1, 24, 24, 24, 24, 0, 'undefined', 'N1478139417184')";

    }


    public function testExecute()
    {
        parent::testExecute();
    }

    protected function assertions()
    {
        $this->assertEquals(1, $this->getMailCollector()->getMessageCount());
    }
}

Setting this up in phpstorm with app/phpunit.xml.dist:

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://ift.tt/1t9p8nW -->
<phpunit xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:noNamespaceSchemaLocation="http://ift.tt/1t9p2wP"
         backupGlobals="false"
         colors="true"
         bootstrap="bootstrap.php.cache"
>
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>

    <!--
    <php>
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    </php>
    -->

    <filter>
        <whitelist>
            <directory>../src</directory>
            <exclude>
                <directory>../src/*/*Bundle/Resources</directory>
                <directory>../src/*/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/Resources</directory>
                <directory>../src/*/Bundle/*Bundle/Tests</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

I find that I cannot execute the test, because "test class is not specified or invalid"

enter image description here

I tried using scope: class, method, but I'm not sure what else could be missing?

Aucun commentaire:

Enregistrer un commentaire