This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi, I'm new in unit testing. But I trying to test every plugin I have made by following this doc. But I got the following error when running phpunit
in the base plugin directory;
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
E
Time: 3.53 seconds, Memory: 23.25Mb
There was 1 error:
1) Rahman\Forum\Tests\Models\TopicTest::testCreateTopic
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: users (SQL: select * from "users" where "users"."deleted_at" is null)
...
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such table: users
...
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
and my test file code is TopicTest.php
.
<?php namespace Rahman\Forum\Tests\Models;
use Rahman\Forum\Models\Topic;
use PluginTestCase;
class TopicTest extends PluginTestCase
{
public function testCreateTopic()
{
$topic = Topic::create(['subject' => 'New topic!']);
$this->assertEquals(1, $topic->id);
}
}
Am I missed something?
Thanks
Last updated
Did you find a solution to this? I'm getting different errors, but I was wondering if you had a working example I could look at..
This should do the trick
https://octobercms.com/docs/plugin/registration#dependency-definitions
Last updated
trying to follow the unit testing documentation, but cant have anything working so far.
php vendor/bin/phpunit
PHPUnit 4.7.7-1-g3467f3b by Sebastian Bergmann and contributors.
Cannot open file "/Users/abcd/Sites/project/site/plugins/acme/project/../../../tests/bootstrap.php".
Last updated
Checkout laravel unit testing.
https://laravel.com/docs/5.1/testing#working-with-databases
Make sure you did the following steps:
- set up test database configuration (because you dont want to test against your development database, dont know how its handled id laravel 5.*)
- in your testcase setUp() method, run all migrations before before every test case (in a laravel unit test u usually do this, not sure if this is the best practise in october)
this are just some basic ideas, what could be wrong.
Last updated
Hi
in case you have this error like @chris10207
php vendor/bin/phpunit
PHPUnit 4.7.7-1-g3467f3b by Sebastian Bergmann and contributors.
Cannot open file "/Users/abcd/Sites/project/site/plugins/acme/project/../../../tests/bootstrap.php".
open the "phpunit.xml" in folder plugin and delete the line
bootstrap="../../../tests/bootstrap.php"
Hmm, I remember getting such errors but don't remember how to fix them sadly. But as an example of how a plugin can be tested, you can take a look at this - https://github.com/pratyushpundir/oc-sublimeStripe.
I know I haven't followed all best practices but this is my very first plugin meant for public use and is still a work in progress.
Last updated
taha.azzabi14703 said:
Hi
in case you have this error like @chris10207
php vendor/bin/phpunit PHPUnit 4.7.7-1-g3467f3b by Sebastian Bergmann and contributors. Cannot open file "/Users/abcd/Sites/project/site/plugins/acme/project/../../../tests/bootstrap.php".
open the "phpunit.xml" in folder plugin and delete the line
bootstrap="../../../tests/bootstrap.php"
I would not delete the bootstrap="../../../tests/bootstrap.php"
piece. It's what loads in the settings required for October's Plugin Test case and other not-exactly-laravel things.
In my test I had an emtpy function setUp(). The result was an error in phpunit saying that the class 'Model' could not be found. The problem appeared to be that I had an empty method setUp() that prevented the parent::setUp() from running. So I changed my setUp().
Now I'm running in to another problem: In one tabel I'm using a composite primary key. If I set that through the standard Schema:: method; the default name october chooses will be too long and my database will throw an error. So I added a raw statement ('ALTER TABLE ....') to the 'up' method of the builder. This works perfectly when I do plugin:refresh on the commandline.
But when it runs though the PluginTestCase class it throws an error "Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "PRIMARY": syntax error (SQL: ALTER TABLE". If I comment this line out while testing, I do not get the error; but then: what are my tests worth? I tried all sorts of back ticks, with or without semi colons, but I'va had no success.
How should I change my statement so that it will pass the plugin:refresh commands on my commandline AND in the PluginTestCase class?
Last updated
1-9 of 9