mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
Avoid destroying the test database in the middle of tests. All tests now pass!
This commit is contained in:
parent
b38026b218
commit
4f0aab6db9
7 changed files with 33 additions and 5 deletions
|
@ -61,7 +61,7 @@ class DeleteGenre extends Job implements SelfHandling, ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
DB::reconnect();
|
||||
$this->beforeHandle();
|
||||
|
||||
// The user who kicked off this job is used when generating revision log entries.
|
||||
Auth::login($this->executingUser);
|
||||
|
|
|
@ -85,7 +85,7 @@ class EncodeTrackFile extends Job implements SelfHandling, ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
DB::reconnect();
|
||||
$this->beforeHandle();
|
||||
|
||||
// Sanity check: was this file just generated, or is it already being processed?
|
||||
if ($this->trackFile->status === TrackFile::STATUS_PROCESSING) {
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
namespace Poniverse\Ponyfm\Jobs;
|
||||
|
||||
use App;
|
||||
use DB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
||||
abstract class Job
|
||||
|
@ -36,4 +38,15 @@ abstract class Job
|
|||
*/
|
||||
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* This method should be called at the beginning of every job's handle()
|
||||
* method. It ensures that we don't lose the in-memory database during
|
||||
* testing by disconnecting from it - which causes tests to fail.
|
||||
*/
|
||||
protected function beforeHandle() {
|
||||
if (App::environment() !== 'testing') {
|
||||
DB::reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class UpdateSearchIndexForEntity extends Job implements SelfHandling, ShouldQueu
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
DB::reconnect();
|
||||
$this->beforeHandle();
|
||||
$this->entity->updateElasticsearchEntrySynchronously();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class UpdateTagsForRenamedGenre extends Job implements SelfHandling, ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
DB::reconnect();
|
||||
$this->beforeHandle();
|
||||
|
||||
// The user who kicked off this job is used when generating revision log entries.
|
||||
Auth::login($this->executingUser);
|
||||
|
|
|
@ -29,6 +29,12 @@ class SetupElasticsearch extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
// As of 2016-02-21, Elasticsearch is not used in tests.
|
||||
// Letting this migration run will blow away all data in it.
|
||||
if (App::environment() === 'testing') {
|
||||
return;
|
||||
}
|
||||
|
||||
$elasticsearch = Elasticsearch::connection();
|
||||
|
||||
$elasticsearch->indices()->create([
|
||||
|
@ -108,6 +114,12 @@ class SetupElasticsearch extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
// As of 2016-02-21, Elasticsearch is not used in tests.
|
||||
// Letting this migration run will blow away all data in it.
|
||||
if (App::environment() === 'testing') {
|
||||
return;
|
||||
}
|
||||
|
||||
$elasticsearch = Elasticsearch::connection();
|
||||
|
||||
$elasticsearch->indices()->delete(['index' => 'ponyfm']);
|
||||
|
|
|
@ -132,7 +132,10 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
* @param array $files
|
||||
*/
|
||||
protected function callUploadWithParameters(array $parameters, array $files = []) {
|
||||
$this->expectsJobs(Poniverse\Ponyfm\Jobs\EncodeTrackFile::class);
|
||||
$this->expectsJobs([
|
||||
Poniverse\Ponyfm\Jobs\EncodeTrackFile::class,
|
||||
Poniverse\Ponyfm\Jobs\UpdateSearchIndexForEntity::class
|
||||
]);
|
||||
$this->user = factory(User::class)->create();
|
||||
|
||||
$file = $this->getTestFileForUpload('ponyfm-test.flac');
|
||||
|
|
Loading…
Reference in a new issue