Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced seeInDatabase query #9292

Closed
brayniverse opened this issue Jun 16, 2015 · 7 comments
Closed

Advanced seeInDatabase query #9292

brayniverse opened this issue Jun 16, 2015 · 7 comments

Comments

@brayniverse
Copy link
Contributor

At the moment it doesn't seem possible to check whether a value != something.

If you change the $data parameter, on this line, to allow for either an array or callable value it becomes possible to provide a more complex query.

Proposed change

/**
 * Assert that a given where condition exists in the database.
 * 
 * @param  string  $table
 * @param  array|callable  $data
 * @param  string  $connection
 * @return $this
 */
protected function seeInDatabase($table, $data, $connection = null)
{
    // ...
}

This will also need to be reflected on lines 239 and 252.

Example use case

$this->seeInDatabase('vehicles', function($query) use ($vehicle)
{
    $query->where('id', $vehicle->id)
        ->whereNotNull('discontinued_at');
});

Would this be beneficial to anybody, are there any circumstance where it could break?

@brayniverse
Copy link
Contributor Author

missingFromDatabase and notSeeInDatabase check whether the data does not exist in the database, which could be used to check whether the following doesn't exist.

[
    'id' => 1,
    'deleted_at' => '2015-19-06'
]
$this->missingFromDatabase('vehicles', ['id' => 1, 'deleted_at' => null]);

However, this doesn't necessarily mean that this does exists in the database.

With the proposed change we can check whether a row exists where deleted_at does not equal null and you don't know what the value is.

@brayniverse
Copy link
Contributor Author

@GrahamCampbell did you close this because nothing has happened in 4 days or because it's a bad idea?

@ibrasho
Copy link
Contributor

ibrasho commented Jun 23, 2015

Send a PR with a suggested implementation.
Issues are for bug reports.
Suggestions should be made with PRs.

@EspadaV8
Copy link
Contributor

Did anything happen with this? Currently trying to test a soft deleted row exists and can't find a way to do WHERE deleted_at IS NOT NULL.

@acorncom
Copy link

I'd love to see this added to the system as well ...

@mehdisbys
Copy link

In the meantime for those in search of a solution, you can still do the following to get the latest version of your model after your submit request or whatever you did to change it :

 $model = Model::find($id) 
 //or 
$model = Model::orderBy('id', 'desc')->first() //Gets the latest record in table - if you don't have the id

And then :

$this->assertNotNull($model->discontinued_at)

Hope that helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants