10 months ago

Testing an expiration date with PHPUnit

Posted 10 months ago by gallib


I'm adding a new feature on a package. Goal is to have an expires_at column on a url table. I'm trying to write some tests for that but I have no idea on how to test that.

More precisely, How can I insert a valid url (with a valid expires_at in the future), and right after try to call this url and get something like "This url is no longer valid".

I could try something like:

/** @test */
public function an_url_could_expire()
        $url = $this->createUrl(['code' => 'abcde', 'expires_at' => Carbon::now()->add('PT10M')]);

    $response = $this->get($url);

    $this->assertArrayHasKey('code', $response['errors']);

But I've no idea on how to tweak the response of $this->get, I don't remember seeing anything similar on laracasts.

Thanks for your help!

Please sign in or create an account to participate in this conversation.