Laravel When Condition on a column

I have a ModelA with columns: name, last_name, email

I want ModelA with the name Test to add an extra where on email

what I tried is the following

$model_a_res = A::when(
function($query){
    return $query->where('name','Test');
},
function ($query) { 
    $query->where('email', 'NOT LIKE', '%@test%');})
->first();

I want this second where to only run on A with column name = Test
however, this is not working.

I tried it with user name Mike and his email [email protected] and he didn’t appear in the result.

some data

id name email

1 Test [email protected] 
2 Test [email protected]
3 Mike [email protected]
4 Mike [email protected]

both 3 and 4 should be in the results
1 and 2 since they have name = Test will have another query which will check if he does have @test in his email if he does he will not be returned
returned Rows are 2, 3, 4