Skip to content

[5.5] Properly test exceptions #19873

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

Merged
merged 1 commit into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/Auth/AuthAccessGateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class GateTest extends TestCase
{
/**
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Callback must be a callable or a 'Class@method'
*/
public function test_gate_throws_exception_on_invalid_callback_type()
{
Expand Down Expand Up @@ -276,6 +277,7 @@ public function test_for_user_method_attaches_a_new_user_to_a_new_gate_instance(

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage You are not an admin.
*/
public function test_authorize_throws_unauthorized_exception()
{
Expand Down
1 change: 1 addition & 0 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public function testSetUserFiresAuthenticatedEvent()

/**
* @expectedException \Illuminate\Auth\AuthenticationException
* @expectedExceptionMessage Unauthenticated.
*/
public function testAuthenticateThrowsWhenUserIsNull()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Auth/AuthPasswordBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function testIfUserIsNotFoundErrorRedirectIsReturned()
}

/**
* @expectedException UnexpectedValueException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage User must implement CanResetPassword interface.
*/
public function testGetUserThrowsExceptionIfUserDoesntImplementCanResetPassword()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Auth/AuthenticateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function setUp()

/**
* @expectedException \Illuminate\Auth\AuthenticationException
* @expectedExceptionMessage Unauthenticated.
*/
public function testDefaultUnauthenticatedThrows()
{
Expand Down Expand Up @@ -81,6 +82,7 @@ public function testSecondaryAuthenticatedUpdatesDefaultDriver()

/**
* @expectedException \Illuminate\Auth\AuthenticationException
* @expectedExceptionMessage Unauthenticated.
*/
public function testMultipleDriversUnauthenticatedThrows()
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Auth/AuthorizeMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function setUp()

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage This action is unauthorized.
*/
public function testSimpleAbilityUnauthorized()
{
Expand Down Expand Up @@ -95,6 +96,7 @@ public function testSimpleAbilityAuthorized()

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage This action is unauthorized.
*/
public function testModelTypeUnauthorized()
{
Expand Down Expand Up @@ -136,6 +138,7 @@ public function testModelTypeAuthorized()

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage This action is unauthorized.
*/
public function testModelUnauthorized()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Broadcasting/BroadcasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function testExtractingParametersWhileCheckingForUserAccess()
}

/**
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @expectedExceptionMessage
*/
public function testNotFoundThrowsHttpException()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cache/ClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function testClearWithStoreArgument()
}

/**
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage
*/
public function testClearWithInvalidStoreArgument()
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ public function testCallWithDependencies()
}

/**
* @expectedException ReflectionException
* @expectedException \ReflectionException
* @expectedExceptionMessage Function ContainerTestCallStub() does not exist
*/
public function testCallWithAtSignBasedClassReferencesWithoutMethodThrowsException()
{
Expand Down Expand Up @@ -986,6 +987,7 @@ public function testContainerCanBindAnyWord()

/**
* @expectedException \Illuminate\Container\EntryNotFoundException
* @expectedExceptionMessage
*/
public function testUnknownEntryThrowsException()
{
Expand Down
6 changes: 4 additions & 2 deletions tests/Database/DatabaseConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function testReadWriteConnectionsNotCreatedUntilNeeded()
}

/**
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage A driver must be specified.
*/
public function testIfDriverIsntSetExceptionIsThrown()
{
Expand All @@ -82,7 +83,8 @@ public function testIfDriverIsntSetExceptionIsThrown()
}

/**
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unsupported driver [foo]
*/
public function testExceptionIsThrownOnUnsupportedDriver()
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Database/DatabaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public function testTransactionMethodRunsSuccessfully()

/**
* @expectedException \Illuminate\Database\QueryException
* @expectedExceptionMessage Deadlock found when trying to get lock (SQL: )
*/
public function testTransactionMethodRetriesOnDeadlock()
{
Expand Down Expand Up @@ -256,6 +257,7 @@ public function testTransactionMethodRollsbackAndThrows()

/**
* @expectedException \Illuminate\Database\QueryException
* @expectedExceptionMessage server has gone away (SQL: foo)
*/
public function testOnLostConnectionPDOIsNotSwappedWithinATransaction()
{
Expand Down Expand Up @@ -309,6 +311,7 @@ public function testRunMethodRetriesOnFailure()

/**
* @expectedException \Illuminate\Database\QueryException
* @expectedExceptionMessage (SQL: ) (SQL: )
*/
public function testRunMethodNeverRetriesIfWithinTransaction()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ public function testGetRelationProperlySetsNestedRelationshipsWithSimilarNames()
}

/**
* @expectedException Illuminate\Database\Eloquent\RelationNotFoundException
* @expectedException \Illuminate\Database\Eloquent\RelationNotFoundException
* @expectedExceptionMessage Call to undefined relationship [invalid] on model [Mockery_18_Illuminate_Database_Eloquent_Model].
*/
public function testGetRelationThrowsException()
{
Expand Down
1 change: 1 addition & 0 deletions tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public function testQueueableCollectionImplementation()

/**
* @expectedException \LogicException
* @expectedExceptionMessage Queueing collections with multiple model types is not supported.
*/
public function testQueueableCollectionImplementationThrowsExceptionOnMultipleModelTypes()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function testItLoadsARelationWithCustomIntermediateAndLocalKey()

/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
* @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost].
*/
public function testFirstOrFailThrowsAnException()
{
Expand All @@ -113,6 +114,7 @@ public function testFirstOrFailThrowsAnException()

/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
* @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost].
*/
public function testFindOrFailThrowsAnException()
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public function testFindOrFail()

/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
* @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\EloquentTestUser] 1
*/
public function testFindOrFailWithSingleIdThrowsModelNotFoundException()
{
Expand All @@ -413,6 +414,7 @@ public function testFindOrFailWithSingleIdThrowsModelNotFoundException()

/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
* @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\EloquentTestUser] 1, 2
*/
public function testFindOrFailWithMultipleIdsThrowsModelNotFoundException()
{
Expand Down Expand Up @@ -866,7 +868,7 @@ public function testSavingJSONFields()
}

/**
* @expectedException Exception
* @expectedException \Exception
*/
public function testSaveOrFailWithDuplicatedEntry()
{
Expand Down
5 changes: 4 additions & 1 deletion tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ public function testFillableOverridesGuarded()

/**
* @expectedException \Illuminate\Database\Eloquent\MassAssignmentException
* @expectedExceptionMessage name
*/
public function testGlobalGuarded()
{
Expand Down Expand Up @@ -1294,7 +1295,8 @@ public function testRemoveMultipleObservableEvents()
}

/**
* @expectedException LogicException
* @expectedException \LogicException
* @expectedExceptionMessage Illuminate\Tests\Database\EloquentModelStub::incorrectRelationStub must return a relationship instance.
*/
public function testGetModelAttributeMethodThrowsExceptionIfNotRelation()
{
Expand Down Expand Up @@ -1541,6 +1543,7 @@ public function testModelAttributeCastingPreservesNull()

/**
* @expectedException \Illuminate\Database\Eloquent\JsonEncodingException
* @expectedExceptionMessage Unable to encode attribute [objectAttribute] for model [Illuminate\Tests\Database\EloquentModelCastingStub] to JSON: Malformed UTF-8 characters, possibly incorrectly encoded.
*/
public function testModelAttributeCastingFailsOnUnencodableData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ public function testMorphToWithTrashed()
}

/**
* @expectedException BadMethodCallException
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Call to undefined method Illuminate\Database\Query\Builder::thisMethodDoesNotExist()
*/
public function testMorphToWithBadMethodCall()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,8 @@ public function testCallTriggersDynamicWhere()
}

/**
* @expectedException BadMethodCallException
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Call to undefined method Illuminate\Database\Query\Builder::noValidMethodHere()
*/
public function testBuilderThrowsExpectedExceptionWithUndefinedMethod()
{
Expand Down
12 changes: 6 additions & 6 deletions tests/Encryption/EncrypterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testWithCustomCipher()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
*/
public function testDoNoAllowLongerKey()
Expand All @@ -54,7 +54,7 @@ public function testDoNoAllowLongerKey()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
*/
public function testWithBadKeyLength()
Expand All @@ -63,7 +63,7 @@ public function testWithBadKeyLength()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
*/
public function testWithBadKeyLengthAlternativeCipher()
Expand All @@ -72,7 +72,7 @@ public function testWithBadKeyLengthAlternativeCipher()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
*/
public function testWithUnsupportedCipher()
Expand All @@ -81,7 +81,7 @@ public function testWithUnsupportedCipher()
}

/**
* @expectedException Illuminate\Contracts\Encryption\DecryptException
* @expectedException \Illuminate\Contracts\Encryption\DecryptException
* @expectedExceptionMessage The payload is invalid.
*/
public function testExceptionThrownWhenPayloadIsInvalid()
Expand All @@ -93,7 +93,7 @@ public function testExceptionThrownWhenPayloadIsInvalid()
}

/**
* @expectedException Illuminate\Contracts\Encryption\DecryptException
* @expectedException \Illuminate\Contracts\Encryption\DecryptException
* @expectedExceptionMessage The MAC is invalid.
*/
public function testExceptionThrownWithDifferentKey()
Expand Down
1 change: 1 addition & 0 deletions tests/Foundation/FoundationAuthorizesRequestsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function test_basic_gate_check()

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage This action is unauthorized.
*/
public function test_exception_is_thrown_if_gate_check_fails()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Foundation/FoundationFormRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function test_validated_method_returns_the_validated_data()

/**
* @expectedException \Illuminate\Validation\ValidationException
* @expectedExceptionMessage The given data failed to pass validation.
*/
public function test_validate_throws_when_validation_fails()
{
Expand All @@ -49,6 +50,7 @@ public function test_validate_throws_when_validation_fails()

/**
* @expectedException \Illuminate\Auth\Access\AuthorizationException
* @expectedExceptionMessage This action is unauthorized.
*/
public function test_validate_method_throws_when_authorization_fails()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Foundation/FoundationHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function testCache()
}

/**
* @expectedException Exception
* @expectedException \Exception
* @expectedExceptionMessage You must specify an expiration time when setting a value in the cache.
*/
public function testCacheThrowsAnExceptionIfAnExpirationIsNotProvided()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/HttpJsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testSetAndRetrieveStatusCode()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Type is not supported
*/
public function testJsonErrorResource()
Expand Down
3 changes: 2 additions & 1 deletion tests/Http/HttpRedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public function testMagicCall()
}

/**
* @expectedException BadMethodCallException
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method [doesNotExist] does not exist on Redirect.
*/
public function testMagicCallException()
{
Expand Down
6 changes: 4 additions & 2 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ public function testBadAcceptHeader()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage Session store not set on request.
*/
public function testSessionMethod()
{
Expand Down Expand Up @@ -687,7 +688,8 @@ public function testFingerprintMethod()
}

/**
* @expectedException RuntimeException
* @expectedException \RuntimeException
* @expectedExceptionMessage Unable to generate fingerprint. Route unavailable.
*/
public function testFingerprintWithoutRoute()
{
Expand Down
1 change: 1 addition & 0 deletions tests/Http/HttpResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function testMagicCall()

/**
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method [doesNotExist] does not exist on Redirect.
*/
public function testMagicCallException()
{
Expand Down
Loading