Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. λ vendorbinphpunit testsUnitReplyTest.php
  2. PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
  3.  
  4. F 1 / 1 (100%)
  5.  
  6. Time: 360 ms, Memory: 12.00MB
  7.  
  8. There was 1 failure:
  9.  
  10. 1) TestsUnitReplyTest::it_has_an_owner
  11. Failed asserting that null is an instance of class "AppUser".
  12.  
  13. C:laragonwwwforumtestsUnitReplyTest.php:19
  14.  
  15. FAILURES!
  16. Tests: 1, Assertions: 1, Failures: 1.
  17.  
  18. <?php
  19.  
  20. namespace TestsUnit;
  21.  
  22. use TestsTestCase;
  23. use IlluminateFoundationTestingDatabaseMigrations;
  24.  
  25.  
  26. class ReplyTest extends TestCase
  27. {
  28. use DatabaseMigrations;
  29.  
  30. /** @test **/
  31. public function it_has_an_owner()
  32. {
  33. $reply = factory('AppUser')->create();
  34.  
  35. $this->assertInstanceOf('AppUser', $reply->owner);
  36. }
  37. }
  38.  
  39. <?php
  40.  
  41. namespace App;
  42.  
  43. use IlluminateDatabaseEloquentModel;
  44.  
  45. class Reply extends Model
  46. {
  47. public function owner()
  48. {
  49. return $this->belongsTo(User::class, 'user_id');
  50. }
  51. }
  52.  
  53. <?php
  54.  
  55. /** @var IlluminateDatabaseEloquentFactory $factory */
  56. $factory->define(AppUser::class, function (FakerGenerator $faker) {
  57. static $password;
  58.  
  59. return [
  60. 'name' => $faker->name,
  61. 'email' => $faker->unique()->safeEmail,
  62. 'password' => $password ?: $password = bcrypt('secret'),
  63. 'remember_token' => str_random(10),
  64. ];
  65. });
  66.  
  67. $factory->define(AppThread::class, function (FakerGenerator $faker) {
  68. static $password;
  69.  
  70. return [
  71. 'user_id' => function() {
  72. return factory('AppUser')->create()->id;
  73. },
  74. 'title' => $faker->sentence,
  75. 'body' => $faker->paragraph
  76. ];
  77. });
  78.  
  79. $factory->define(AppReply::class, function (FakerGenerator $faker) {
  80. static $password;
  81.  
  82. return [
  83. 'thread_id' => function() {
  84. return factory('AppThread')->create()->id;
  85. },
  86.  
  87. 'user_id' => function() {
  88. return factory('AppUser')->create()->id;
  89. },
  90. 'body' => $faker->paragraph
  91. ];
  92. });
  93.  
  94. <div class="col-md-8 col-md-offset-2">
  95. @foreach ($thread->replies as $reply)
  96. <div class="panel-heading">
  97. <a href="#">
  98. {{ $reply->owner->name }}
  99. </a>
  100. said {{ $reply->created_at->diffForHumans() }} ...
  101. </div>
  102.  
  103. <div class="panel panel-default">
  104. <div class="panel-body">
  105. {{ $reply->body }}
  106. </div>
  107. </div>
  108. @endforeach
  109. </div>
  110.  
  111. $reply = factory('AppReply')->create();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement