E
E
Evgenii Borovoi2020-06-10 09:10:36
Laravel
Evgenii Borovoi, 2020-06-10 09:10:36

How to connect a live database in setUpBeforeClass() and setUp() in phpunit?

I do not need to create a new database from migrations and all that, I just need to create / delete a user before testing.

class ApiUserCreateErrorsTest extends TestCase
{
public static function setUpBeforeClass(): void
    {
        parent::setUpBeforeClass(); 

        User::where('email', '[email protected]')->delete();
...


Swears like this
1) Tests\Unit\API\ApiUserCreateErrorsTest::testEmptyEmail
Error: Call to a member function connection() on null in /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php: 1253

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-06-10
@EugeneOne77

In setUp() this will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question