How to use the method setup from PHPUnit in Laravel 5.8

前端 未结 2 1993
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 14:07

I used to use the method setup of PHPUnit to create a instance for my test methods. But in Laravel 5.8 I can\'t do it

I\'ve tried both ways, and it\'s works makes a

相关标签:
2条回答
  • 2021-01-06 14:45

    This is what i did and it help

    /**
         * Set up the test
         */
        public function setUp(): void
        {
            parent::setUp();
            $this->faker = Faker::create();
        }
    
        /**
         * Reset the migrations
         */
        public function tearDown(): void
        {
            $this->artisan('migrate:reset');
            parent::tearDown();
        }
    

    Not stating the return type to void in the functions

    0 讨论(0)
  • 2021-01-06 14:51

    Laravel 5.8 added the void typehint to the return type of the setUp method.
    So you have to declare that like this:

    public function setUp(): void
    {
        // you should also call parent::setUp() to properly boot
        // the Laravel application in your tests
        $this->instance = new MyService;
    }
    

    Note the : void after the function arguments to state the return type of that function

    0 讨论(0)
提交回复
热议问题