psaunders's avatar

PHPunit not handling cache flush

I have an issue with an intermittent fault in my unit tests, it's kind of annoying because it only started happening recently on some tests I wrote a while ago, the system seems to be having an issue with file upload tests suddenly.

 /** @test **/
   public function update_article_when_only_sections_change(){
      $this->clearDatabase();

      $section1 = factory(App\Section\Profile::class)->create();
      $section2 = factory(App\Section\Profile::class)->create();
 
      $article = factory(App\Article::class)->create([
            'sections' => array($section1->toArray(),$section2->toArray())
      ]);

      $sections = $article->sections->toArray();

      // New Section
      $section3 = factory(App\Section\Profile::class)->make()->toArray();

      //Article array that has no changes apart from with the sections
      $articleArray['id']         = $article['id'];
      $articleArray['sections']   = $sections;
      $articleArray['sections'][] = $section3;

      //Getting the filenames of the deleted files
      $section1File = \App\File::find($sections[0]['content']['file_id'])->filename;
      $section2File = \App\File::find($sections[1]['content']['file_id'])->filename;

      $articleArray['sections'][0]['_method'] = 'DELETE';
      $articleArray['sections'][1]['_method'] = 'DELETE';

      //Should delete the other sections
      Log::info('Test prepared');
      $response = $this->call('PATCH', '/article/'.$article['id'],$articleArray);
      // dd($article);

      $this->assertEquals(200, $response->status());

      $article = $article->fresh();

      $this->assertEquals(1,$article->typedSections->count());

      $this->visit('/article/'.$article['id'])
          ->dontSee($section1File)
          ->dontSee($section2File)
          ->see($article->typedSections[0]->image->filename); //Causes PHPunit failure sometimes
   }

Basically if fails to see the updated image file, but the image is there if you load the page. Same thing happens if the change is a linked text section. Also its intermittent, it almost always passes if you run just that test suite, but it fails if you run the whole thing. If I manually put a Cache::flush() into the phpunit scripts it seems to work, but there already is one attached to the model events.

0 likes
0 replies

Please or to participate in this conversation.