-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception from Translate plugin when doing Unit Test #546
Comments
The testing class you are using isn't properly tearing down the application after each test run. Please verify that you have the latest code. Additionally, we're making some pretty big improvements to testing in the L6 upgrade branch, so perhaps you should wait until octobercms/october#4919 is merged into the upgrade branch and then use the upgrade branch to build your tests on. |
thanks @LukeTowers I can wait for the next upgrade branch for this tests, sure, my base test case class looks like the example from the doc. /**
* Set up function, called before each test.
*
* @return void
*/
public function setUp()
{
parent::setUp();
// set up plugins
$pluginManager = PluginManager::instance();
$pluginManager->registerAll(true);
$pluginManager->bootAll(true);
// disable mailer
Mail::pretend();
}
/**
* Tear down function, called after each test.
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
// clean up plugins
$pluginManager = PluginManager::instance();
$pluginManager->unregisterAll();
// close all mocks
Mockery::close();
} |
@chrisvidal try adding this method: static $initialized = false;
protected function runOctoberUpCommand()
{
if (static::$initialized) {
return;
}
static::$initialized = true;
// Get all tables and views then drop them to reset the database
$views = array_keys(\DB::connection()->getDoctrineSchemaManager()->listViews());
$tables = \DB::connection()->getDoctrineSchemaManager()->listTableNames();
foreach ($tables as $table) {
\Schema::drop($table);
}
foreach ($views as $view) {
\DB::statement("DROP VIEW $view");
}
// Initialize the database
\Artisan::call('october:up');
} |
thanks @LukeTowers adding this in my base test class, still gives me the error
|
@chrisvidal alright, got another idea for you. Remove that code, it's not really applicable unless you're using SQL views. Instead, add in \October\Rain\Halcyon\Model::clearBootedModels();
\October\Rain\Halcyon\Model::flushEventListeners();
\October\Rain\Halcyon\Model::clearExtendedClasses(); to your |
Related: #509 |
oh this is working @LukeTowers thanks so much mate |
damn! after few positive testing, a new exception is happening on the tearDown() method
and
|
@chrisvidal also add
|
thanks @LukeTowers
|
Should resolve some issues in testing where models are not properly reset to a blank state. Refs: rainlab/translate-plugin#546, rainlab/translate-plugin#509
@chrisvidal are you sure it's accessing the correct database? @bennothommo any ideas here? |
@chrisvidal Another couple of things to check:
|
@chrisvidal has this been resolved? Can we close this? |
I haven't had time to look deeper into it. And deciding to wait for the Laravel 6 upgrade. @bennothommo I am using MySQL |
Given that my plugin is depending on a depending who is depending on Rainlab.Translate.
I am writing (well at least trying) to write some unit test for my plugin, testing API endpoints mostly, and I got this exception:
The test class manages to run the
setUp()
method.The text was updated successfully, but these errors were encountered: