Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- λ vendorbinphpunit testsUnitReplyTest.php
- PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
- F 1 / 1 (100%)
- Time: 360 ms, Memory: 12.00MB
- There was 1 failure:
- 1) TestsUnitReplyTest::it_has_an_owner
- Failed asserting that null is an instance of class "AppUser".
- C:laragonwwwforumtestsUnitReplyTest.php:19
- FAILURES!
- Tests: 1, Assertions: 1, Failures: 1.
- <?php
- namespace TestsUnit;
- use TestsTestCase;
- use IlluminateFoundationTestingDatabaseMigrations;
- class ReplyTest extends TestCase
- {
- use DatabaseMigrations;
- /** @test **/
- public function it_has_an_owner()
- {
- $reply = factory('AppUser')->create();
- $this->assertInstanceOf('AppUser', $reply->owner);
- }
- }
- <?php
- namespace App;
- use IlluminateDatabaseEloquentModel;
- class Reply extends Model
- {
- public function owner()
- {
- return $this->belongsTo(User::class, 'user_id');
- }
- }
- <?php
- /** @var IlluminateDatabaseEloquentFactory $factory */
- $factory->define(AppUser::class, function (FakerGenerator $faker) {
- static $password;
- return [
- 'name' => $faker->name,
- 'email' => $faker->unique()->safeEmail,
- 'password' => $password ?: $password = bcrypt('secret'),
- 'remember_token' => str_random(10),
- ];
- });
- $factory->define(AppThread::class, function (FakerGenerator $faker) {
- static $password;
- return [
- 'user_id' => function() {
- return factory('AppUser')->create()->id;
- },
- 'title' => $faker->sentence,
- 'body' => $faker->paragraph
- ];
- });
- $factory->define(AppReply::class, function (FakerGenerator $faker) {
- static $password;
- return [
- 'thread_id' => function() {
- return factory('AppThread')->create()->id;
- },
- 'user_id' => function() {
- return factory('AppUser')->create()->id;
- },
- 'body' => $faker->paragraph
- ];
- });
- <div class="col-md-8 col-md-offset-2">
- @foreach ($thread->replies as $reply)
- <div class="panel-heading">
- <a href="#">
- {{ $reply->owner->name }}
- </a>
- said {{ $reply->created_at->diffForHumans() }} ...
- </div>
- <div class="panel panel-default">
- <div class="panel-body">
- {{ $reply->body }}
- </div>
- </div>
- @endforeach
- </div>
- $reply = factory('AppReply')->create();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement