unit testing - Writing a test in Laravel to determine if ORM items are in the correct order -


I wrote a test to draw 10 articles from my database. I then wrote the code to pass the exam and this work Does. However, now I want to write a test to make sure that 10 articles dragging from the database are based on descending order created_at . I'm not sure how to know about this.

Test Method:

  public function testPullTenArticles () {for ($ i = 0; $ i & lt; 20; $ i ++) {$ temp article = New paragraph; $ TempArticle- & gt; Save (); } $ This- & gt; Emphasizing value (10, calculation ($ this-> article-> getArticles (10))); }   

Actual method:

  public function getArticles ($ count) {$ article = Article :: take ($ count) - & gt; get (); Return $ article; }    

If you are using by order Retrieve your items, then you do not need to check it - those who are good people who are Laravel & amp; Corrective code has already been done.

You can order your archive in this way:

  $ articles = article :: orderBy ("created_at", "desc") - & gt; Le ($ count) - & gt; Find ();    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -