Search code examples
phpsqlitelaravelphpspec

How to insert a sample data with PHPSpec and Laravel


I change my environment to testing on basespec with sqlite as driver and store in the memory.

function it_should_validate()
    {
        // Create the user
        $data = array('email' => 'test@gmail.com', 'password' => 'password', 'remember' => false);

        $this->validate($data)->shouldBe(true);
    }

How do i insert information to the testing database whenever i run the test? Right now the test fails because it always return false;


Solution

  • What you're trying to do is integration testing.

    PhpSpec is a tool for unit testing. It puts a big emphasis on testing in isolation. That means, that the only object that's created is the object being tested. All its dependencies should be stubbed or mocked.

    In other words there should be no database involved in specs you write.

    You didn't show the full example of a class you're trying to spec, so it's hard to advice how your spec should look like.

    Adviced reading: