From 8adcfea864f6fa6da8c7827de00c16686626342b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 13 May 2022 11:20:49 -0700 Subject: [PATCH] chore: add support for PHPUnit 8 (#5252) --- .github/emulator/start-emulator.sh | 4 +- .../bigtable-emulator-system-tests.yaml | 4 +- .../datastore-emulator-system-tests.yaml | 6 +- .../firestore-emulator-system-tests.yaml | 4 +- .../pubsub-emulator-system-tests.yaml | 6 +- .../spanner-emulator-system-tests.yaml | 6 +- AccessApproval/composer.json | 3 +- AccessContextManager/composer.json | 3 +- AiPlatform/composer.json | 3 +- AnalyticsAdmin/composer.json | 3 +- AnalyticsData/composer.json | 3 +- ApiGateway/composer.json | 3 +- ApigeeConnect/composer.json | 3 +- AppEngineAdmin/composer.json | 3 +- ArtifactRegistry/composer.json | 3 +- Asset/composer.json | 3 +- AssuredWorkloads/composer.json | 3 +- AutoMl/composer.json | 3 +- AutoMl/tests/System/V1/AutoMlSmokeTest.php | 2 +- .../tests/System/V1beta1/AutoMlSmokeTest.php | 4 +- BigQuery/composer.json | 3 +- BigQuery/phpunit-snippets.xml.dist | 2 +- BigQuery/tests/Perf/BigQueryTest.php | 4 +- BigQuery/tests/Snippet/BigQueryClientTest.php | 2 +- .../Snippet/CopyJobConfigurationTest.php | 2 +- BigQuery/tests/Snippet/DatasetTest.php | 2 +- .../Snippet/ExtractJobConfigurationTest.php | 2 +- BigQuery/tests/Snippet/InsertResponseTest.php | 2 +- BigQuery/tests/Snippet/JobTest.php | 2 +- .../Snippet/LoadJobConfigurationTest.php | 2 +- BigQuery/tests/Snippet/ModelTest.php | 2 +- .../Snippet/QueryJobConfigurationTest.php | 2 +- BigQuery/tests/Snippet/QueryResultsTest.php | 2 +- BigQuery/tests/Snippet/RoutineTest.php | 2 +- BigQuery/tests/Snippet/TableTest.php | 2 +- BigQuery/tests/System/BigQueryTestCase.php | 2 +- .../tests/System/LoadDataAndQueryTest.php | 10 +- BigQuery/tests/System/ManageDatasetsTest.php | 8 +- BigQuery/tests/System/ManageModelsTest.php | 4 +- BigQuery/tests/System/ManageRoutinesTest.php | 4 +- BigQuery/tests/System/ManageTablesTest.php | 8 +- BigQuery/tests/System/RegionalizationTest.php | 38 +++-- BigQuery/tests/Unit/BigNumericTest.php | 6 +- BigQuery/tests/Unit/BigQueryClientTest.php | 4 +- BigQuery/tests/Unit/Connection/RestTest.php | 4 +- .../tests/Unit/CopyJobConfigurationTest.php | 4 +- BigQuery/tests/Unit/DatasetTest.php | 4 +- .../Unit/ExtractJobConfigurationTest.php | 4 +- .../tests/Unit/JobConfigurationTraitTest.php | 11 +- BigQuery/tests/Unit/JobTest.php | 4 +- BigQuery/tests/Unit/JobWaitTraitTest.php | 14 +- .../tests/Unit/LoadJobConfigurationTest.php | 4 +- BigQuery/tests/Unit/ModelTest.php | 4 +- BigQuery/tests/Unit/NumericTest.php | 6 +- .../tests/Unit/QueryJobConfigurationTest.php | 4 +- BigQuery/tests/Unit/QueryResultsTest.php | 4 +- BigQuery/tests/Unit/RoutineTest.php | 4 +- BigQuery/tests/Unit/TableTest.php | 38 +++-- BigQuery/tests/Unit/ValueMapperTest.php | 18 +-- BigQueryConnection/composer.json | 3 +- BigQueryDataTransfer/composer.json | 3 +- BigQueryReservation/composer.json | 3 +- BigQueryStorage/composer.json | 3 +- Bigtable/composer.json | 5 +- Bigtable/phpunit-snippets.xml.dist | 2 +- Bigtable/tests/Conformance/ReadRowsTest.php | 4 +- Bigtable/tests/Snippet/ChunkFormatterTest.php | 2 +- .../Filter/Builder/FamilyFilterTest.php | 2 +- .../Snippet/Filter/Builder/KeyFilterTest.php | 2 +- .../Filter/Builder/LimitFilterTest.php | 2 +- .../Filter/Builder/OffsetFilterTest.php | 2 +- .../Filter/Builder/QualifierFilterTest.php | 2 +- .../Filter/Builder/TimestampFilterTest.php | 2 +- .../Filter/Builder/ValueFilterTest.php | 2 +- .../tests/Snippet/Filter/ChainFilterTest.php | 2 +- .../Snippet/Filter/ConditionFilterTest.php | 2 +- .../Snippet/Filter/InterleaveFilterTest.php | 2 +- Bigtable/tests/Snippet/TableTest.php | 2 +- .../BigtableInstanceAdminClientTest.php | 6 +- Bigtable/tests/System/BigtableTestCase.php | 4 +- .../tests/System/CheckAndMutateRowTest.php | 4 +- Bigtable/tests/System/FilterTest.php | 4 +- .../tests/System/ReadModifyWriteRowTest.php | 4 +- Bigtable/tests/System/ReadRowsTest.php | 4 +- Bigtable/tests/System/SampleRowKeysTest.php | 4 +- Bigtable/tests/Unit/BigtableClientTest.php | 4 +- Bigtable/tests/Unit/ChunkFormatterTest.php | 140 ++++++++---------- Bigtable/tests/Unit/DataUtilTest.php | 14 +- .../Unit/Filter/Builder/FamilyFilterTest.php | 4 +- .../Unit/Filter/Builder/KeyFilterTest.php | 21 +-- .../Unit/Filter/Builder/LimitFilterTest.php | 4 +- .../Unit/Filter/Builder/OffsetFilterTest.php | 4 +- .../Filter/Builder/QualifierFilterTest.php | 4 +- .../tests/Unit/Filter/Builder/RangeTest.php | 63 ++++---- .../Unit/Filter/Builder/RegexTraitTest.php | 14 +- .../Unit/Filter/Builder/ValueFilterTest.php | 4 +- .../tests/Unit/Filter/ChainFilterTest.php | 4 +- .../tests/Unit/Filter/ConditionFilterTest.php | 12 +- .../Unit/Filter/InterleaveFilterTest.php | 4 +- .../Unit/Filter/QualifierRangeFilterTest.php | 4 +- .../Unit/Filter/TimestampRangeFilterTest.php | 4 +- .../Unit/Filter/ValueRangeFilterTest.php | 4 +- Bigtable/tests/Unit/MutationsTest.php | 4 +- .../Unit/ReadModifyWriteRowRulesTest.php | 4 +- Bigtable/tests/Unit/SmartRetriesTest.php | 35 +++-- Bigtable/tests/Unit/TableTest.php | 56 ++++--- Billing/composer.json | 3 +- BillingBudgets/composer.json | 3 +- BinaryAuthorization/composer.json | 3 +- Build/composer.json | 3 +- CertificateManager/composer.json | 3 +- Channel/composer.json | 3 +- Compute/composer.json | 3 +- Compute/tests/System/V1/SmokeTest.php | 3 + ContactCenterInsights/composer.json | 3 +- Container/composer.json | 3 +- .../tests/System/ClusterManagerClientTest.php | 6 +- ContainerAnalysis/composer.json | 3 +- Core/composer.json | 3 +- Core/phpunit-snippets.xml.dist | 2 +- Core/src/Testing/GcTestListener.php | 12 +- .../Snippet/Coverage/ResultPrinter.php | 75 ---------- Core/src/Testing/Snippet/SnippetTestCase.php | 4 +- Core/src/Testing/System/SystemTestCase.php | 2 +- Core/src/Testing/TestHelpers.php | 2 +- Core/tests/Snippet/BlobTest.php | 2 +- Core/tests/Snippet/Compute/MetadataTest.php | 2 +- Core/tests/Snippet/DurationTest.php | 2 +- Core/tests/Snippet/GeoPointTest.php | 2 +- Core/tests/Snippet/Iam/IamTest.php | 2 +- Core/tests/Snippet/Iam/PolicyBuilderTest.php | 9 +- Core/tests/Snippet/Int64Test.php | 2 +- .../LongRunning/LongRunningOperationTest.php | 2 +- Core/tests/Snippet/ServiceBuilderTest.php | 2 +- .../Testing/Snippet/Parser/ParserTest.php | 2 +- .../Testing/System/SystemTestCaseTest.php | 16 +- Core/tests/Snippet/TimestampTest.php | 2 +- Core/tests/System/Batch/BatchRunnerTest.php | 13 +- Core/tests/Unit/AnonymousCredentialsTest.php | 4 +- Core/tests/Unit/ArrayTraitTest.php | 12 +- .../tests/Unit/Batch/BatchDaemonTraitTest.php | 4 +- Core/tests/Unit/Batch/BatchRunnerTest.php | 12 +- Core/tests/Unit/Batch/BatchTraitTest.php | 17 ++- .../Unit/Batch/HandleFailureTraitTest.php | 18 ++- .../Unit/Batch/InMemoryConfigStorageTest.php | 17 ++- Core/tests/Unit/Batch/JobConfigTest.php | 4 +- .../Unit/Batch/OpisClosureSerializerTest.php | 4 +- Core/tests/Unit/Batch/RetryTest.php | 8 +- Core/tests/Unit/Batch/SimpleJobTraitTest.php | 8 +- .../Unit/Batch/SysvConfigStorageTest.php | 6 +- Core/tests/Unit/Batch/SysvProcessorTest.php | 11 +- Core/tests/Unit/CallTraitTest.php | 10 +- Core/tests/Unit/ClientTraitTest.php | 44 +++--- .../Readers/HttpHandlerReaderTest.php | 4 +- Core/tests/Unit/Compute/MetadataTest.php | 4 +- .../Unit/ConcurrencyControlTraitTest.php | 4 +- Core/tests/Unit/DurationTest.php | 4 +- Core/tests/Unit/EmulatorTraitTest.php | 4 +- Core/tests/Unit/ExponentialBackoffTest.php | 4 +- Core/tests/Unit/GeoPointTest.php | 12 +- Core/tests/Unit/GrpcRequestWrapperTest.php | 16 +- Core/tests/Unit/GrpcTraitTest.php | 10 +- Core/tests/Unit/Iam/IamTest.php | 12 +- Core/tests/Unit/Iam/PolicyBuilderTest.php | 50 +++---- Core/tests/Unit/JsonTraitTest.php | 17 ++- Core/tests/Unit/Lock/CommonLockTrait.php | 8 +- Core/tests/Unit/Lock/FlockLockTest.php | 30 ++-- Core/tests/Unit/Lock/SemaphoreLockTest.php | 30 ++-- .../Unit/Logger/AppEngineFlexHandlerTest.php | 23 +-- .../OperationResponseTraitTest.php | 4 +- .../Unit/Report/EmptyMetadataProviderTest.php | 4 +- .../Report/SimpleMetadataProviderTest.php | 4 +- Core/tests/Unit/RequestBuilderTest.php | 12 +- Core/tests/Unit/RequestWrapperTest.php | 43 +++--- Core/tests/Unit/RestTraitTest.php | 11 +- Core/tests/Unit/RetryDeciderTraitTest.php | 4 +- Core/tests/Unit/ServicesNotFoundTest.php | 12 +- Core/tests/Unit/SysvTraitTest.php | 4 +- Core/tests/Unit/TimestampTest.php | 4 +- .../Unit/Upload/MultipartUploaderTest.php | 17 ++- .../Unit/Upload/ResumableUploaderTest.php | 27 ++-- .../Unit/Upload/SignedUrlUploaderTest.php | 4 +- .../Unit/Upload/StreamableUploaderTest.php | 17 ++- Core/tests/Unit/UriTraitTest.php | 4 +- Core/tests/Unit/ValidateTraitTest.php | 12 +- Core/tests/Unit/WhitelistTraitTest.php | 4 +- Core/unit-bootstrap.php | 2 - DataCatalog/composer.json | 3 +- DataFusion/composer.json | 3 +- DataLabeling/composer.json | 3 +- Dataflow/composer.json | 3 +- Dataplex/composer.json | 3 +- Dataproc/composer.json | 3 +- .../System/ClusterControllerClientTest.php | 6 +- DataprocMetastore/composer.json | 3 +- Datastore/composer.json | 3 +- Datastore/phpunit-snippets.xml.dist | 2 +- Datastore/tests/Snippet/BlobTest.php | 2 +- .../tests/Snippet/DatastoreClientTest.php | 8 +- .../Snippet/DatastoreSessionHandlerTest.php | 13 +- Datastore/tests/Snippet/EntityTest.php | 2 +- Datastore/tests/Snippet/GeoPointTest.php | 2 +- Datastore/tests/Snippet/KeyTest.php | 10 +- .../tests/Snippet/Query/GqlQueryTest.php | 4 +- Datastore/tests/Snippet/Query/QueryTest.php | 2 +- .../tests/Snippet/ReadOnlyTransactionTest.php | 2 +- Datastore/tests/Snippet/TransactionTest.php | 2 +- Datastore/tests/System/AllocateKeyTest.php | 7 +- Datastore/tests/System/DatastoreTestCase.php | 6 +- .../System/QueryResultPaginationTest.php | 8 +- Datastore/tests/System/RunQueryTest.php | 4 +- Datastore/tests/Unit/Connection/GrpcTest.php | 9 +- Datastore/tests/Unit/Connection/RestTest.php | 4 +- Datastore/tests/Unit/DatastoreClientTest.php | 11 +- .../Unit/DatastoreSessionHandlerTest.php | 54 +++---- Datastore/tests/Unit/DatastoreTraitTest.php | 9 +- Datastore/tests/Unit/EntityMapperTest.php | 48 +++--- Datastore/tests/Unit/EntityTest.php | 4 +- Datastore/tests/Unit/KeyTest.php | 28 ++-- Datastore/tests/Unit/OperationTest.php | 62 ++++---- Datastore/tests/Unit/Query/GqlQueryTest.php | 4 +- Datastore/tests/Unit/Query/QueryTest.php | 12 +- Datastore/tests/Unit/TransactionTest.php | 4 +- DatastoreAdmin/composer.json | 3 +- Debugger/composer.json | 3 +- Debugger/phpunit-snippets.xml.dist | 2 +- Debugger/tests/Snippet/AgentTest.php | 2 +- Debugger/tests/Snippet/DaemonTest.php | 2 +- Debugger/tests/Snippet/DebuggeeTest.php | 2 +- Debugger/tests/Snippet/DebuggerClientTest.php | 2 +- Debugger/tests/System/BasicTest.php | 7 +- Debugger/tests/System/E2ETest.php | 14 +- Debugger/tests/Unit/AgentTest.php | 8 +- .../FileBreakpointStorageTest.php | 4 +- .../SysvBreakpointStorageTest.php | 4 +- .../tests/Unit/BreakpointValidationTest.php | 4 +- Debugger/tests/Unit/CliDaemonTest.php | 28 ++-- Debugger/tests/Unit/Connection/GrpcTest.php | 4 +- Debugger/tests/Unit/Connection/RestTest.php | 4 +- Debugger/tests/Unit/DaemonTest.php | 4 +- Debugger/tests/Unit/DebuggeeTest.php | 4 +- Debugger/tests/Unit/DebuggerClientTest.php | 4 +- .../tests/Unit/SourceLocationResolverTest.php | 4 +- Debugger/tests/Unit/VariableTableTest.php | 12 +- Deploy/composer.json | 3 +- Dialogflow/composer.json | 3 +- Dlp/composer.json | 3 +- Dms/composer.json | 3 +- DocumentAi/composer.json | 3 +- Domains/composer.json | 3 +- ErrorReporting/composer.json | 3 +- ErrorReporting/tests/Unit/BootstrapTest.php | 4 +- EssentialContacts/composer.json | 3 +- Eventarc/composer.json | 3 +- EventarcPublishing/composer.json | 3 +- Filestore/composer.json | 3 +- Firestore/composer.json | 3 +- Firestore/phpunit-snippets.xml.dist | 2 +- .../tests/Snippet/CollectionReferenceTest.php | 2 +- .../tests/Snippet/DocumentReferenceTest.php | 2 +- .../tests/Snippet/DocumentSnapshotTest.php | 2 +- Firestore/tests/Snippet/FieldPathTest.php | 2 +- Firestore/tests/Snippet/FieldValueTest.php | 2 +- .../tests/Snippet/FirestoreClientTest.php | 2 +- .../Snippet/FirestoreSessionHandlerTest.php | 13 +- Firestore/tests/Snippet/QuerySnapshotTest.php | 2 +- Firestore/tests/Snippet/QueryTest.php | 2 +- Firestore/tests/Snippet/TransactionTest.php | 2 +- Firestore/tests/Snippet/WriteBatchTest.php | 2 +- .../V1/FirestoreAdminClientSmokeTest.php | 2 +- .../System/DocumentAndCollectionTest.php | 2 +- Firestore/tests/System/FieldValueTest.php | 2 +- Firestore/tests/System/FirestoreTestCase.php | 2 +- .../tests/System/GetAllDocumentsTest.php | 4 +- Firestore/tests/System/QueryTest.php | 2 +- Firestore/tests/System/TransactionTest.php | 2 +- Firestore/tests/System/ValueMapperTest.php | 6 +- .../tests/Unit/CollectionReferenceTest.php | 4 +- Firestore/tests/Unit/ConformanceTest.php | 4 +- Firestore/tests/Unit/Connection/GrpcTest.php | 4 +- .../tests/Unit/DocumentReferenceTest.php | 8 +- Firestore/tests/Unit/DocumentSnapshotTest.php | 34 ++--- Firestore/tests/Unit/FieldPathTest.php | 11 +- Firestore/tests/Unit/FirestoreClientTest.php | 36 +++-- .../Unit/FirestoreSessionHandlerTest.php | 39 +++-- Firestore/tests/Unit/PathTraitTest.php | 4 +- Firestore/tests/Unit/QuerySnapshotTest.php | 4 +- Firestore/tests/Unit/QueryTest.php | 77 +++++----- Firestore/tests/Unit/SnapshotTraitTest.php | 17 ++- Firestore/tests/Unit/TransactionTest.php | 4 +- Firestore/tests/Unit/ValueMapperTest.php | 26 ++-- Firestore/tests/Unit/WriteBatchTest.php | 48 +++--- Functions/composer.json | 3 +- Gaming/composer.json | 3 +- GkeConnectGateway/composer.json | 3 +- GkeHub/composer.json | 3 +- Grafeas/composer.json | 3 +- IamCredentials/composer.json | 3 +- Iap/composer.json | 3 +- Ids/composer.json | 3 +- Iot/composer.json | 3 +- Kms/composer.json | 3 +- Language/composer.json | 3 +- Language/phpunit-snippets.xml.dist | 2 +- Language/tests/Snippet/AnnotationTest.php | 2 +- Language/tests/Snippet/LanguageClientTest.php | 4 +- Language/tests/System/LanguageTestCase.php | 4 +- Language/tests/Unit/AnnotationTest.php | 4 +- Language/tests/Unit/Connection/RestTest.php | 4 +- Language/tests/Unit/LanguageClientTest.php | 4 +- LifeSciences/composer.json | 3 +- Logging/composer.json | 3 +- Logging/phpunit-snippets.xml.dist | 2 +- Logging/tests/Perf/LoggingPerfTest.php | 4 +- Logging/tests/Snippet/LoggerTest.php | 2 +- Logging/tests/Snippet/LoggingClientTest.php | 2 +- Logging/tests/Snippet/MetricTest.php | 2 +- Logging/tests/Snippet/PsrLoggerTest.php | 2 +- Logging/tests/Snippet/SinkTest.php | 2 +- Logging/tests/System/LoggingTestCase.php | 4 +- Logging/tests/System/ManageSinksTest.php | 2 +- Logging/tests/Unit/Connection/GrpcTest.php | 4 +- Logging/tests/Unit/Connection/RestTest.php | 4 +- Logging/tests/Unit/LoggerTest.php | 12 +- Logging/tests/Unit/LoggingClientTest.php | 11 +- Logging/tests/Unit/MetricTest.php | 4 +- Logging/tests/Unit/PsrLoggerBatchTest.php | 9 +- .../tests/Unit/PsrLoggerCompatibilityTest.php | 17 ++- Logging/tests/Unit/PsrLoggerTest.php | 63 ++++---- Logging/tests/Unit/SinkTest.php | 4 +- ManagedIdentities/composer.json | 3 +- MediaTranslation/composer.json | 3 +- Memcache/composer.json | 3 +- Monitoring/composer.json | 3 +- NetworkConnectivity/composer.json | 3 +- NetworkManagement/composer.json | 3 +- NetworkSecurity/composer.json | 3 +- Notebooks/composer.json | 3 +- OrchestrationAirflow/composer.json | 3 +- OrgPolicy/composer.json | 3 +- OsConfig/composer.json | 3 +- OsLogin/composer.json | 3 +- .../System/V1/OsLoginServiceClientTest.php | 6 +- .../V1beta/OsLoginServiceClientTest.php | 6 +- PolicyTroubleshooter/composer.json | 3 +- PrivateCatalog/composer.json | 3 +- Profiler/composer.json | 3 +- PubSub/composer.json | 3 +- PubSub/phpunit-snippets.xml.dist | 2 +- PubSub/tests/Snippet/BatchPublisherTest.php | 2 +- PubSub/tests/Snippet/MessageBuilderTest.php | 2 +- PubSub/tests/Snippet/MessageTest.php | 7 +- PubSub/tests/Snippet/PubSubClientTest.php | 2 +- PubSub/tests/Snippet/SchemaTest.php | 2 +- PubSub/tests/Snippet/SnapshotTest.php | 2 +- PubSub/tests/Snippet/SubscriptionTest.php | 10 +- PubSub/tests/Snippet/TopicTest.php | 2 +- PubSub/tests/System/ManageIAMPoliciesTest.php | 4 +- PubSub/tests/System/PubSubTestCase.php | 4 +- PubSub/tests/System/SchemaTest.php | 2 +- PubSub/tests/Unit/Connection/GrpcTest.php | 4 +- PubSub/tests/Unit/Connection/RestTest.php | 4 +- .../tests/Unit/IncomingMessageTraitTest.php | 12 +- PubSub/tests/Unit/MessageBuilderTest.php | 8 +- PubSub/tests/Unit/MessageTest.php | 11 +- PubSub/tests/Unit/PubSubClientTest.php | 16 +- PubSub/tests/Unit/ResourceNameTraitTest.php | 22 +-- PubSub/tests/Unit/SchemaTest.php | 4 +- PubSub/tests/Unit/SnapshotTest.php | 12 +- PubSub/tests/Unit/SubscriptionTest.php | 22 +-- PubSub/tests/Unit/TopicTest.php | 12 +- RecaptchaEnterprise/composer.json | 3 +- RecommendationEngine/composer.json | 3 +- Recommender/composer.json | 3 +- Redis/composer.json | 3 +- .../tests/System/V1/CloudRedisClientTest.php | 6 +- .../System/V1beta1/CloudRedisClientTest.php | 6 +- .../V1/CloudRedisClientPartialVeneerTest.php | 11 +- .../CloudRedisClientPartialVeneerTest.php | 11 +- ResourceManager/composer.json | 3 +- ResourceSettings/composer.json | 3 +- Retail/composer.json | 3 +- Scheduler/composer.json | 3 +- .../System/V1/CloudSchedulerSmokeTest.php | 6 +- .../V1beta1/CloudSchedulerSmokeTest.php | 6 +- SecretManager/composer.json | 3 +- SecurityCenter/composer.json | 3 +- SecurityPrivateCa/composer.json | 3 +- ServiceControl/composer.json | 3 +- ServiceDirectory/composer.json | 3 +- ServiceManagement/composer.json | 3 +- ServiceUsage/composer.json | 3 +- Shell/composer.json | 3 +- Spanner/composer.json | 3 +- Spanner/phpunit-snippets.xml.dist | 2 +- Spanner/tests/Snippet/ArrayTypeTest.php | 2 +- Spanner/tests/Snippet/BackupTest.php | 4 +- .../tests/Snippet/Batch/BatchClientTest.php | 2 +- .../tests/Snippet/Batch/BatchSnapshotTest.php | 2 +- .../Snippet/Batch/QueryPartitionTest.php | 2 +- .../tests/Snippet/Batch/ReadPartitionTest.php | 2 +- Spanner/tests/Snippet/BatchDmlResultTest.php | 2 +- Spanner/tests/Snippet/BytesTest.php | 2 +- Spanner/tests/Snippet/CommitTimestampTest.php | 2 +- Spanner/tests/Snippet/DatabaseTest.php | 6 +- Spanner/tests/Snippet/DateTest.php | 2 +- Spanner/tests/Snippet/DurationTest.php | 2 +- .../Snippet/InstanceConfigurationTest.php | 2 +- Spanner/tests/Snippet/InstanceTest.php | 6 +- Spanner/tests/Snippet/KeyRangeTest.php | 2 +- Spanner/tests/Snippet/KeySetTest.php | 2 +- Spanner/tests/Snippet/ResultTest.php | 10 +- Spanner/tests/Snippet/SnapshotTest.php | 2 +- Spanner/tests/Snippet/SpannerClientTest.php | 2 +- Spanner/tests/Snippet/StructTypeTest.php | 2 +- Spanner/tests/Snippet/StructValueTest.php | 2 +- Spanner/tests/Snippet/TimestampTest.php | 2 +- Spanner/tests/Snippet/TransactionTest.php | 2 +- .../Snippet/TransactionalReadMethodsTest.php | 4 +- Spanner/tests/StubCreationTrait.php | 2 - Spanner/tests/System/BackupTest.php | 7 +- Spanner/tests/System/BatchTest.php | 4 +- Spanner/tests/System/LargeReadTest.php | 4 +- Spanner/tests/System/OperationsTest.php | 4 +- Spanner/tests/System/PgQueryTest.php | 11 +- Spanner/tests/System/PgReadTest.php | 85 +++++------ Spanner/tests/System/PgTransactionTest.php | 4 +- Spanner/tests/System/PgWriteTest.php | 24 +-- Spanner/tests/System/QueryTest.php | 6 +- Spanner/tests/System/ReadTest.php | 19 ++- Spanner/tests/System/SnapshotTest.php | 13 +- Spanner/tests/System/SpannerPgTestCase.php | 2 +- Spanner/tests/System/SpannerTestCase.php | 2 +- Spanner/tests/System/TransactionTest.php | 4 +- Spanner/tests/System/WriteTest.php | 24 +-- Spanner/tests/Unit/ArrayTypeTest.php | 6 +- Spanner/tests/Unit/BackupTest.php | 6 +- Spanner/tests/Unit/Batch/BatchClientTest.php | 20 +-- .../tests/Unit/Batch/BatchSnapshotTest.php | 13 +- Spanner/tests/Unit/BytesTest.php | 8 +- Spanner/tests/Unit/CommitTimestampTest.php | 4 +- Spanner/tests/Unit/Connection/GrpcTest.php | 4 +- .../tests/Unit/Connection/IamDatabaseTest.php | 4 +- .../tests/Unit/Connection/IamInstanceTest.php | 4 +- .../Connection/LongRunningConnectionTest.php | 4 +- Spanner/tests/Unit/DatabaseTest.php | 46 +++--- Spanner/tests/Unit/DateTest.php | 8 +- Spanner/tests/Unit/DurationTest.php | 4 +- .../Unit/GapicBackoff/GapicBackoffTest.php | 4 +- .../tests/Unit/InstanceConfigurationTest.php | 4 +- Spanner/tests/Unit/InstanceTest.php | 11 +- Spanner/tests/Unit/KeyRangeTest.php | 21 ++- Spanner/tests/Unit/KeySetTest.php | 13 +- Spanner/tests/Unit/NumericTest.php | 6 +- Spanner/tests/Unit/OperationTest.php | 4 +- Spanner/tests/Unit/ResultTest.php | 16 +- .../Unit/Session/CacheSessionPoolTest.php | 21 ++- Spanner/tests/Unit/SnapshotTest.php | 16 +- Spanner/tests/Unit/SpannerClientTest.php | 9 +- Spanner/tests/Unit/StructTypeTest.php | 17 ++- Spanner/tests/Unit/StructValueTest.php | 4 +- Spanner/tests/Unit/TimestampTest.php | 8 +- .../TransactionConfigurationTraitTest.php | 31 ++-- Spanner/tests/Unit/TransactionTest.php | 36 ++--- Spanner/tests/Unit/TransactionTypeTest.php | 21 ++- Spanner/tests/Unit/ValueMapperTest.php | 75 +++++----- Speech/composer.json | 3 +- Speech/phpunit-snippets.xml.dist | 2 +- Speech/tests/Snippet/OperationTest.php | 2 +- Speech/tests/Snippet/ResultTest.php | 2 +- Speech/tests/Snippet/SpeechClientTest.php | 2 +- Speech/tests/Snippet/V1/SpeechClientTest.php | 2 +- Speech/tests/Unit/Connection/RestTest.php | 4 +- Speech/tests/Unit/OperationTest.php | 4 +- Speech/tests/Unit/ResultTest.php | 4 +- Speech/tests/Unit/SpeechClientTest.php | 12 +- Speech/tests/Unit/SpeechHelpersTraitTest.php | 4 +- .../Unit/V1/SpeechClientExtensionTest.php | 4 +- SqlAdmin/composer.json | 3 +- Storage/composer.json | 3 +- Storage/phpunit-snippets.xml.dist | 2 +- Storage/tests/Snippet/AclTest.php | 2 +- Storage/tests/Snippet/BucketTest.php | 16 +- Storage/tests/Snippet/CreatedHmacKeyTest.php | 2 +- Storage/tests/Snippet/HmacKeyTest.php | 2 +- Storage/tests/Snippet/LifecycleTest.php | 2 +- Storage/tests/Snippet/NotificationTest.php | 2 +- Storage/tests/Snippet/StorageClientTest.php | 2 +- Storage/tests/Snippet/StorageObjectTest.php | 36 ++--- Storage/tests/System/HmacKeyTest.php | 4 +- Storage/tests/System/IamConfigurationTest.php | 33 ++--- Storage/tests/System/IamTest.php | 10 +- Storage/tests/System/KmsTest.php | 17 ++- Storage/tests/System/ManageBucketsTest.php | 7 +- Storage/tests/System/ManageObjectsTest.php | 14 +- Storage/tests/System/PostPolicyTest.php | 2 +- Storage/tests/System/RequesterPaysTest.php | 18 ++- Storage/tests/System/SignedUrlTest.php | 8 +- Storage/tests/System/StorageTestCase.php | 2 +- .../tests/System/StreamWrapper/AppendTest.php | 4 +- .../System/StreamWrapper/DirectoryTest.php | 8 +- .../tests/System/StreamWrapper/FlushTest.php | 4 +- .../tests/System/StreamWrapper/ImageTest.php | 4 +- .../tests/System/StreamWrapper/ReadTest.php | 2 +- .../tests/System/StreamWrapper/RenameTest.php | 4 +- .../StreamWrapper/StreamWrapperTestCase.php | 8 +- .../System/StreamWrapper/UrlStatTest.php | 4 +- .../tests/System/StreamWrapper/WriteTest.php | 4 +- Storage/tests/System/UploadObjectsTest.php | 8 +- Storage/tests/Unit/AclTest.php | 12 +- Storage/tests/Unit/BucketTest.php | 49 +++--- Storage/tests/Unit/ConformanceTest.php | 8 +- Storage/tests/Unit/Connection/RestTest.php | 4 +- Storage/tests/Unit/CreatedHmacKeyTest.php | 4 +- Storage/tests/Unit/EncryptionTraitTest.php | 4 +- Storage/tests/Unit/HmacKeyTest.php | 4 +- Storage/tests/Unit/LifecycleTest.php | 12 +- Storage/tests/Unit/NotificationTest.php | 4 +- Storage/tests/Unit/RequesterPaysTest.php | 4 +- Storage/tests/Unit/SigningHelperTest.php | 42 +++--- Storage/tests/Unit/StorageClientTest.php | 10 +- Storage/tests/Unit/StorageObjectTest.php | 22 +-- Storage/tests/Unit/StreamWrapperTest.php | 18 ++- StorageTransfer/composer.json | 3 +- Talent/composer.json | 3 +- Tasks/composer.json | 3 +- TextToSpeech/composer.json | 3 +- Tpu/composer.json | 3 +- Trace/composer.json | 3 +- Trace/phpunit-snippets.xml.dist | 2 +- Trace/tests/Snippet/SpanTest.php | 9 +- Trace/tests/Snippet/TraceClientTest.php | 7 +- Trace/tests/Snippet/TraceTest.php | 7 +- Trace/tests/Unit/Connection/GrpcTest.php | 4 +- Trace/tests/Unit/Connection/RestTest.php | 4 +- Trace/tests/Unit/SpanTest.php | 11 +- Trace/tests/Unit/TimestampTraitTest.php | 5 +- Trace/tests/Unit/TraceClientTest.php | 4 +- Trace/tests/Unit/TraceTest.php | 9 +- Translate/composer.json | 3 +- Translate/phpunit-snippets.xml.dist | 2 +- .../tests/Snippet/V2/TranslateClientTest.php | 2 +- Translate/tests/System/V2/TranslateTest.php | 50 ++++--- .../tests/System/V2/TranslateTestCase.php | 4 +- .../tests/Unit/V2/Connection/RestTest.php | 4 +- .../tests/Unit/V2/TranslateClientTest.php | 4 +- VideoIntelligence/composer.json | 3 +- .../V1/VideoIntelligenceServiceClientTest.php | 4 +- VideoLiveStream/composer.json | 3 +- VideoStitcher/composer.json | 3 +- VideoTranscoder/composer.json | 3 +- Vision/composer.json | 3 +- Vision/phpunit-snippets.xml.dist | 2 +- .../tests/Snippet/Annotation/CropHintTest.php | 2 +- .../tests/Snippet/Annotation/DocumentTest.php | 2 +- .../tests/Snippet/Annotation/EntityTest.php | 2 +- .../Snippet/Annotation/Face/LandmarksTest.php | 2 +- Vision/tests/Snippet/Annotation/FaceTest.php | 2 +- .../Annotation/ImagePropertiesTest.php | 2 +- .../Snippet/Annotation/SafeSearchTest.php | 2 +- .../Snippet/Annotation/Web/WebEntityTest.php | 2 +- .../Snippet/Annotation/Web/WebImageTest.php | 2 +- .../Snippet/Annotation/Web/WebPageTest.php | 2 +- Vision/tests/Snippet/Annotation/WebTest.php | 2 +- Vision/tests/Snippet/AnnotationTest.php | 5 +- .../Snippet/V1/ImageAnnotatorClientTest.php | 4 +- Vision/tests/Snippet/VisionClientTest.php | 2 +- Vision/tests/System/AnnotationsTest.php | 9 +- Vision/tests/System/VisionTestCase.php | 4 +- Vision/tests/Unit/Annotation/CropHintTest.php | 4 +- .../Unit/Annotation/Face/LandmarksTest.php | 4 +- Vision/tests/Unit/Annotation/FaceTest.php | 4 +- .../Unit/Annotation/LikelihoodTraitTest.php | 12 +- .../tests/Unit/Annotation/SafeSearchTest.php | 4 +- .../Unit/Annotation/Web/WebEntityTest.php | 4 +- .../Unit/Annotation/Web/WebImageTest.php | 4 +- .../tests/Unit/Annotation/Web/WebPageTest.php | 4 +- Vision/tests/Unit/Annotation/WebTest.php | 4 +- Vision/tests/Unit/Connection/RestTest.php | 4 +- Vision/tests/Unit/ImageTest.php | 8 +- .../V1/ImageAnnotatorClientExtensionTest.php | 4 +- Vision/tests/Unit/VisionClientTest.php | 16 +- Vision/tests/Unit/VisionHelpersTraitTest.php | 9 +- VmMigration/composer.json | 3 +- VpcAccess/composer.json | 3 +- WebRisk/composer.json | 3 +- WebSecurityScanner/composer.json | 3 +- Workflows/composer.json | 3 +- composer.json | 6 +- .../template-phpunit-snippets.xml.dist.txt | 2 +- dev/src/DocGenerator/Parser/CodeParser.php | 10 +- dev/tests/Unit/ComponentManagerTest.php | 4 +- dev/tests/Unit/Split/GitHubTest.php | 4 +- dev/tests/Unit/Split/ReleaseNotesTest.php | 9 +- dev/tests/Unit/Split/SplitInstallTest.php | 14 +- dev/tests/Unit/Split/SplitTest.php | 4 +- phpcs-ruleset.xml | 2 + phpunit-php5-snippets.xml.dist | 1 - phpunit-php5.xml.dist | 6 +- phpunit-snippets.xml.dist | 1 - phpunit.xml.dist | 34 ++--- .../System/ServiceWhitelist/WhitelistTest.php | 7 +- 602 files changed, 2457 insertions(+), 2201 deletions(-) delete mode 100644 Core/src/Testing/Snippet/Coverage/ResultPrinter.php diff --git a/.github/emulator/start-emulator.sh b/.github/emulator/start-emulator.sh index ee10d785cce4..cf27bb3972f8 100755 --- a/.github/emulator/start-emulator.sh +++ b/.github/emulator/start-emulator.sh @@ -1,9 +1,9 @@ #!/bin/sh -eux -docker pull -q gcr.io/google.com/cloudsdktool/cloud-sdk:342.0.0-emulators +docker pull -q gcr.io/google.com/cloudsdktool/cloud-sdk:384.0.1-emulators CONTAINER=`docker run \ -d \ -p 8085:8085 \ - gcr.io/google.com/cloudsdktool/cloud-sdk:342.0.0-emulators gcloud beta emulators $1 start --host-port=0.0.0.0:8085 --project=emulator-project` + gcr.io/google.com/cloudsdktool/cloud-sdk:384.0.1-emulators gcloud beta emulators $1 start --host-port=0.0.0.0:8085 --project=emulator-project` sleep 10 docker logs $CONTAINER diff --git a/.github/workflows/bigtable-emulator-system-tests.yaml b/.github/workflows/bigtable-emulator-system-tests.yaml index c87d4f836ca8..96831012f00e 100644 --- a/.github/workflows/bigtable-emulator-system-tests.yaml +++ b/.github/workflows/bigtable-emulator-system-tests.yaml @@ -26,7 +26,9 @@ jobs: - name: Install dependencies run: | - composer update --prefer-dist --no-interaction --no-suggest -d Bigtable/ + composer config minimum-stability dev -d Bigtable/ + composer config repositories.local path "../Core" -d Bigtable + composer require "google/cloud-core:*" -d Bigtable/ - name: Run system tests run: | diff --git a/.github/workflows/datastore-emulator-system-tests.yaml b/.github/workflows/datastore-emulator-system-tests.yaml index 41a3bca692b0..1a9d9c742660 100644 --- a/.github/workflows/datastore-emulator-system-tests.yaml +++ b/.github/workflows/datastore-emulator-system-tests.yaml @@ -1,3 +1,4 @@ +name: Run Datastore System Tests With Emulator on: push: branches: @@ -7,7 +8,6 @@ on: pull_request: paths: - 'Datastore/**' -name: Run Datastore System Tests With Emulator jobs: test: runs-on: ubuntu-latest @@ -26,7 +26,9 @@ jobs: - name: Install dependencies run: | - composer update --prefer-dist --no-interaction --no-suggest -d Datastore/ + composer config minimum-stability dev -d Datastore/ + composer config repositories.local path "../Core" -d Datastore + composer require "google/cloud-core:*" -d Datastore/ - name: Run system tests run: | diff --git a/.github/workflows/firestore-emulator-system-tests.yaml b/.github/workflows/firestore-emulator-system-tests.yaml index a238e7f61e46..4148be837eed 100644 --- a/.github/workflows/firestore-emulator-system-tests.yaml +++ b/.github/workflows/firestore-emulator-system-tests.yaml @@ -26,7 +26,9 @@ jobs: - name: Install dependencies run: | - composer update --prefer-dist --no-interaction --no-suggest -d Firestore/ + composer config minimum-stability dev -d Firestore/ + composer config repositories.local path "../Core" -d Firestore + composer require "google/cloud-core:*" -d Firestore/ - name: Run system tests run: | diff --git a/.github/workflows/pubsub-emulator-system-tests.yaml b/.github/workflows/pubsub-emulator-system-tests.yaml index 46250b528d68..fd957cf5919d 100644 --- a/.github/workflows/pubsub-emulator-system-tests.yaml +++ b/.github/workflows/pubsub-emulator-system-tests.yaml @@ -22,11 +22,13 @@ jobs: with: php-version: '7.4' tools: pecl - extensions: grpc-1.38.0 + extensions: grpc - name: Install dependencies run: | - composer update --prefer-dist --no-interaction --no-suggest -d PubSub/ + composer config minimum-stability dev -d PubSub/ + composer config repositories.local path "../Core" -d PubSub + composer require "google/cloud-core:*" -d PubSub/ - name: Run system tests run: | diff --git a/.github/workflows/spanner-emulator-system-tests.yaml b/.github/workflows/spanner-emulator-system-tests.yaml index 4fa1e4ca238f..0114b55beffe 100644 --- a/.github/workflows/spanner-emulator-system-tests.yaml +++ b/.github/workflows/spanner-emulator-system-tests.yaml @@ -9,7 +9,7 @@ on: - 'Spanner/**' name: Run Spanner System Tests With Emulator jobs: - php-test: + test: runs-on: ubuntu-latest services: @@ -39,10 +39,12 @@ jobs: with: php-version: '7.4' tools: pecl - extensions: bcmath, grpc-1.37.1 + extensions: bcmath, grpc - name: Install dependencies run: | + composer config minimum-stability dev -d Spanner/ + composer config repositories.local --json '{"type":"path", "url": "../Core", "options": {"versions": {"google/cloud-core": "1.45"}}}' -d Spanner composer update --prefer-dist --no-interaction --no-suggest -d Spanner/ - name: Run system tests diff --git a/AccessApproval/composer.json b/AccessApproval/composer.json index b22a4ac5c5c1..fa35d5405fd0 100644 --- a/AccessApproval/composer.json +++ b/AccessApproval/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/AccessContextManager/composer.json b/AccessContextManager/composer.json index a86196cafb93..9f7fa4cca411 100644 --- a/AccessContextManager/composer.json +++ b/AccessContextManager/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "conflict": { diff --git a/AiPlatform/composer.json b/AiPlatform/composer.json index aa7757957e1b..6c8db5e11b14 100644 --- a/AiPlatform/composer.json +++ b/AiPlatform/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/AnalyticsAdmin/composer.json b/AnalyticsAdmin/composer.json index 62ed6cd1d314..9ba87c171af0 100644 --- a/AnalyticsAdmin/composer.json +++ b/AnalyticsAdmin/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/AnalyticsData/composer.json b/AnalyticsData/composer.json index ba3644b461da..2a6985076f6e 100644 --- a/AnalyticsData/composer.json +++ b/AnalyticsData/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ApiGateway/composer.json b/ApiGateway/composer.json index 1a5cd83a6d91..d09633c9994a 100644 --- a/ApiGateway/composer.json +++ b/ApiGateway/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ApigeeConnect/composer.json b/ApigeeConnect/composer.json index fabecfdbd256..6261c32b3440 100644 --- a/ApigeeConnect/composer.json +++ b/ApigeeConnect/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/AppEngineAdmin/composer.json b/AppEngineAdmin/composer.json index 3b831b33f2c6..123493289351 100644 --- a/AppEngineAdmin/composer.json +++ b/AppEngineAdmin/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ArtifactRegistry/composer.json b/ArtifactRegistry/composer.json index 2062e8ecf323..41c97b2235b7 100644 --- a/ArtifactRegistry/composer.json +++ b/ArtifactRegistry/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Asset/composer.json b/Asset/composer.json index 6403e32b8feb..73a640b294b6 100644 --- a/Asset/composer.json +++ b/Asset/composer.json @@ -30,7 +30,8 @@ "google/cloud-osconfig": "^0.5" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/AssuredWorkloads/composer.json b/AssuredWorkloads/composer.json index bf74c9d5d66d..3d50cff9c4e5 100644 --- a/AssuredWorkloads/composer.json +++ b/AssuredWorkloads/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/AutoMl/composer.json b/AutoMl/composer.json index 818f6ed1b563..049e2ba01de9 100644 --- a/AutoMl/composer.json +++ b/AutoMl/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/AutoMl/tests/System/V1/AutoMlSmokeTest.php b/AutoMl/tests/System/V1/AutoMlSmokeTest.php index 6f8339d2d57d..626fbd21d2ba 100644 --- a/AutoMl/tests/System/V1/AutoMlSmokeTest.php +++ b/AutoMl/tests/System/V1/AutoMlSmokeTest.php @@ -35,7 +35,7 @@ class AutoMlSmokeTest extends SystemTestCase private static $location = 'us-central1'; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/AutoMl/tests/System/V1beta1/AutoMlSmokeTest.php b/AutoMl/tests/System/V1beta1/AutoMlSmokeTest.php index 1c5b33c66273..5e640cd3da66 100644 --- a/AutoMl/tests/System/V1beta1/AutoMlSmokeTest.php +++ b/AutoMl/tests/System/V1beta1/AutoMlSmokeTest.php @@ -35,7 +35,7 @@ class AutoMlSmokeTest extends SystemTestCase private static $location = 'us-central1'; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; @@ -88,7 +88,7 @@ public function testAutoMl(AutoMlClient $automl) public function clientsProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return self::$clients; } } diff --git a/BigQuery/composer.json b/BigQuery/composer.json index d4cd8316f346..922cc1038387 100644 --- a/BigQuery/composer.json +++ b/BigQuery/composer.json @@ -8,7 +8,8 @@ "ramsey/uuid": "^3.0|^4.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/BigQuery/phpunit-snippets.xml.dist b/BigQuery/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/BigQuery/phpunit-snippets.xml.dist +++ b/BigQuery/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/BigQuery/tests/Perf/BigQueryTest.php b/BigQuery/tests/Perf/BigQueryTest.php index e9bff4591c49..69ebb711c722 100644 --- a/BigQuery/tests/Perf/BigQueryTest.php +++ b/BigQuery/tests/Perf/BigQueryTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\BigQuery\Tests\Perf; use Google\Cloud\BigQuery\BigQueryClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -29,7 +29,7 @@ class BigQueryTest extends TestCase private $client; - public function setUp() + public function set_up() { $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $this->client = new BigQueryClient([ diff --git a/BigQuery/tests/Snippet/BigQueryClientTest.php b/BigQuery/tests/Snippet/BigQueryClientTest.php index 2d18bffa2a65..b655c735b337 100644 --- a/BigQuery/tests/Snippet/BigQueryClientTest.php +++ b/BigQuery/tests/Snippet/BigQueryClientTest.php @@ -75,7 +75,7 @@ class BigQueryClientTest extends SnippetTestCase ] ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(BigQueryTestClient::class); diff --git a/BigQuery/tests/Snippet/CopyJobConfigurationTest.php b/BigQuery/tests/Snippet/CopyJobConfigurationTest.php index d9ee96c93e7b..6ceeab4378f3 100644 --- a/BigQuery/tests/Snippet/CopyJobConfigurationTest.php +++ b/BigQuery/tests/Snippet/CopyJobConfigurationTest.php @@ -34,7 +34,7 @@ class CopyJobConfigurationTest extends SnippetTestCase private $config; - public function setUp() + public function set_up() { $this->config = new CopyJobConfiguration( self::PROJECT_ID, diff --git a/BigQuery/tests/Snippet/DatasetTest.php b/BigQuery/tests/Snippet/DatasetTest.php index 90f1d9f0d9b9..0c46d059173f 100644 --- a/BigQuery/tests/Snippet/DatasetTest.php +++ b/BigQuery/tests/Snippet/DatasetTest.php @@ -35,7 +35,7 @@ class DatasetTest extends SnippetTestCase private $connection; private $mapper; - public function setUp() + public function set_up() { $this->mapper = new ValueMapper(false); $this->identity = ['datasetId' => 'id', 'projectId' => 'projectId']; diff --git a/BigQuery/tests/Snippet/ExtractJobConfigurationTest.php b/BigQuery/tests/Snippet/ExtractJobConfigurationTest.php index c319460b4df8..e560e16ac559 100644 --- a/BigQuery/tests/Snippet/ExtractJobConfigurationTest.php +++ b/BigQuery/tests/Snippet/ExtractJobConfigurationTest.php @@ -35,7 +35,7 @@ class ExtractJobConfigurationTest extends SnippetTestCase private $config; - public function setUp() + public function set_up() { $this->config = new ExtractJobConfiguration( self::PROJECT_ID, diff --git a/BigQuery/tests/Snippet/InsertResponseTest.php b/BigQuery/tests/Snippet/InsertResponseTest.php index 78e9dcb4fd2a..af011b33c1ec 100644 --- a/BigQuery/tests/Snippet/InsertResponseTest.php +++ b/BigQuery/tests/Snippet/InsertResponseTest.php @@ -49,7 +49,7 @@ class InsertResponseTest extends SnippetTestCase ] ]; - public function setUp() + public function set_up() { $this->insertResponse = new InsertResponse($this->info, $this->rows); } diff --git a/BigQuery/tests/Snippet/JobTest.php b/BigQuery/tests/Snippet/JobTest.php index 92cdd5db8103..85de120184f9 100644 --- a/BigQuery/tests/Snippet/JobTest.php +++ b/BigQuery/tests/Snippet/JobTest.php @@ -32,7 +32,7 @@ class JobTest extends SnippetTestCase private $identity; private $connection; - public function setUp() + public function set_up() { $this->identity = ['jobId' => 'id', 'projectId' => 'projectId']; $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/BigQuery/tests/Snippet/LoadJobConfigurationTest.php b/BigQuery/tests/Snippet/LoadJobConfigurationTest.php index e5b425f55770..68c4c6378fc3 100644 --- a/BigQuery/tests/Snippet/LoadJobConfigurationTest.php +++ b/BigQuery/tests/Snippet/LoadJobConfigurationTest.php @@ -35,7 +35,7 @@ class LoadJobConfigurationTest extends SnippetTestCase private $config; - public function setUp() + public function set_up() { $this->config = new LoadJobConfiguration( self::PROJECT_ID, diff --git a/BigQuery/tests/Snippet/ModelTest.php b/BigQuery/tests/Snippet/ModelTest.php index f5439f52906c..5ef0f5c6495b 100644 --- a/BigQuery/tests/Snippet/ModelTest.php +++ b/BigQuery/tests/Snippet/ModelTest.php @@ -40,7 +40,7 @@ class ModelTest extends SnippetTestCase const MODEL_ID = 'myModelId'; const JOB_ID = 'myJob'; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->model = TestHelpers::stub(Model::class, [ diff --git a/BigQuery/tests/Snippet/QueryJobConfigurationTest.php b/BigQuery/tests/Snippet/QueryJobConfigurationTest.php index 9920e6e71824..341937ee11ef 100644 --- a/BigQuery/tests/Snippet/QueryJobConfigurationTest.php +++ b/BigQuery/tests/Snippet/QueryJobConfigurationTest.php @@ -35,7 +35,7 @@ class QueryJobConfigurationTest extends SnippetTestCase private $config; - public function setUp() + public function set_up() { $this->config = new QueryJobConfiguration( new ValueMapper(false), diff --git a/BigQuery/tests/Snippet/QueryResultsTest.php b/BigQuery/tests/Snippet/QueryResultsTest.php index 01012a37a4c6..36f75a3b4169 100644 --- a/BigQuery/tests/Snippet/QueryResultsTest.php +++ b/BigQuery/tests/Snippet/QueryResultsTest.php @@ -38,7 +38,7 @@ class QueryResultsTest extends SnippetTestCase private $connection; private $qr; - public function setUp() + public function set_up() { $this->info = [ 'totalBytesProcessed' => 3, diff --git a/BigQuery/tests/Snippet/RoutineTest.php b/BigQuery/tests/Snippet/RoutineTest.php index 4ef8b54733a2..e19c3556d1b2 100644 --- a/BigQuery/tests/Snippet/RoutineTest.php +++ b/BigQuery/tests/Snippet/RoutineTest.php @@ -36,7 +36,7 @@ class RoutineTest extends SnippetTestCase private $routine; private $identity; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->identity = [ diff --git a/BigQuery/tests/Snippet/TableTest.php b/BigQuery/tests/Snippet/TableTest.php index 512af7dde528..b9161341a6f7 100644 --- a/BigQuery/tests/Snippet/TableTest.php +++ b/BigQuery/tests/Snippet/TableTest.php @@ -50,7 +50,7 @@ class TableTest extends SnippetTestCase private $table; private $mapper; - public function setUp() + public function set_up() { $this->info = [ 'rows' => [ diff --git a/BigQuery/tests/System/BigQueryTestCase.php b/BigQuery/tests/System/BigQueryTestCase.php index d528075ffbe9..ab00d70bd0ba 100644 --- a/BigQuery/tests/System/BigQueryTestCase.php +++ b/BigQuery/tests/System/BigQueryTestCase.php @@ -34,7 +34,7 @@ class BigQueryTestCase extends SystemTestCase protected static $table; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/BigQuery/tests/System/LoadDataAndQueryTest.php b/BigQuery/tests/System/LoadDataAndQueryTest.php index 73680dfb7804..bbe21c73e7e4 100644 --- a/BigQuery/tests/System/LoadDataAndQueryTest.php +++ b/BigQuery/tests/System/LoadDataAndQueryTest.php @@ -35,7 +35,7 @@ class LoadDataAndQueryTest extends BigQueryTestCase private $row; private $geographyPattern; - public function setUp() + public function set_up() { $this->row = [ 'Name' => 'Dave', @@ -89,7 +89,7 @@ public function testInsertRowToTable() $this->assertEquals($expectedRow, $actualRow); $this->assertEquals((string) $expectedBytes, (string) $actualBytes); - $this->assertRegExp($this->geographyPattern, (string) $actualGeography); + $this->assertMatchesRegularExpression($this->geographyPattern, (string) $actualGeography); } /** @@ -136,7 +136,7 @@ public function testRunQuery($useLegacySql) $this->assertEquals($spells['Properties'][0]['Name'], $actualRow['Spells_Properties_Name']); $this->assertEquals($spells['Properties'][0]['Power'], $actualRow['Spells_Properties_Power']); $this->assertEquals((string) $spells['Icon'], (string) $actualRow['Spells_Icon']); - $this->assertRegExp($this->geographyPattern, (string) $actualRow['Location']); + $this->assertMatchesRegularExpression($this->geographyPattern, (string) $actualRow['Location']); } else { $expectedRow = $this->row; $expectedBytes = $expectedRow['Spells'][0]['Icon']; @@ -151,7 +151,7 @@ public function testRunQuery($useLegacySql) $this->assertEquals($expectedRow, $actualRow); $this->assertEquals((string) $expectedBytes, (string) $actualBytes); - $this->assertRegExp($this->geographyPattern, (string) $actualGeography); + $this->assertMatchesRegularExpression($this->geographyPattern, (string) $actualGeography); } } @@ -294,7 +294,7 @@ public function testRunQueryWithNamedParameters() $this->assertEquals($params, $actualRow); $this->assertEquals((string) $bytes, (string) $actualBytes); - $this->assertRegExp($geographyPattern, (string) $actualGeography); + $this->assertMatchesRegularExpression($geographyPattern, (string) $actualGeography); } public function testRunQueryWithPositionalParameters() diff --git a/BigQuery/tests/System/ManageDatasetsTest.php b/BigQuery/tests/System/ManageDatasetsTest.php index 7f03a8ce8826..1441b4793693 100644 --- a/BigQuery/tests/System/ManageDatasetsTest.php +++ b/BigQuery/tests/System/ManageDatasetsTest.php @@ -18,6 +18,7 @@ namespace Google\Cloud\BigQuery\Tests\System; use Google\Cloud\Core\Testing\System\KeyManager; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery @@ -25,6 +26,8 @@ */ class ManageDatasetsTest extends BigQueryTestCase { + use ExpectException; + const KEY_RING_ID = 'bq-kms-kr'; const CRYPTO_KEY_ID = 'bq-dataset-key1'; @@ -142,11 +145,10 @@ public function testSetDatasetDefaultEncryption() $this->assertEquals($keyName, $info['defaultEncryptionConfiguration']['kmsKeyName']); } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testUpdateDatasetConcurrentUpdateFails() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $data = [ 'friendlyName' => 'foo', 'etag' => 'blah' diff --git a/BigQuery/tests/System/ManageModelsTest.php b/BigQuery/tests/System/ManageModelsTest.php index 2b4ac2776390..d6cc56fb1e86 100644 --- a/BigQuery/tests/System/ManageModelsTest.php +++ b/BigQuery/tests/System/ManageModelsTest.php @@ -37,9 +37,9 @@ class ManageModelsTest extends BigQueryTestCase private static $keyName1; private static $keyName2; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$modelId = uniqid(self::TESTING_PREFIX); diff --git a/BigQuery/tests/System/ManageRoutinesTest.php b/BigQuery/tests/System/ManageRoutinesTest.php index 016239a11c2c..bf529793f52d 100644 --- a/BigQuery/tests/System/ManageRoutinesTest.php +++ b/BigQuery/tests/System/ManageRoutinesTest.php @@ -27,9 +27,9 @@ class ManageRoutinesTest extends BigQueryTestCase { private static $routines = []; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); for ($i = 0; $i < 2; $i++) { $routineId = uniqid(self::TESTING_PREFIX); diff --git a/BigQuery/tests/System/ManageTablesTest.php b/BigQuery/tests/System/ManageTablesTest.php index f53ffd8018c5..cf4f7bf847e3 100644 --- a/BigQuery/tests/System/ManageTablesTest.php +++ b/BigQuery/tests/System/ManageTablesTest.php @@ -20,6 +20,7 @@ use Google\Cloud\BigQuery\BigQueryClient; use Google\Cloud\BigQuery\Table; use Google\Cloud\Core\ExponentialBackoff; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery @@ -27,6 +28,8 @@ */ class ManageTablesTest extends BigQueryTestCase { + use ExpectException; + public function testListTables() { $foundTables = []; @@ -132,11 +135,10 @@ public function testUpdateTable() $this->assertEquals($metadata['friendlyName'], $info['friendlyName']); } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testUpdateTableConcurrentUpdateFails() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $data = [ 'friendlyName' => 'foo', 'etag' => 'blah' diff --git a/BigQuery/tests/System/RegionalizationTest.php b/BigQuery/tests/System/RegionalizationTest.php index 8798ea6cfd3d..63e664351efb 100644 --- a/BigQuery/tests/System/RegionalizationTest.php +++ b/BigQuery/tests/System/RegionalizationTest.php @@ -17,12 +17,16 @@ namespace Google\Cloud\BigQuery\Tests\System; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; + /** * @group bigquery * @group bigquery-regionalization */ class RegionalizationTest extends BigQueryTestCase { + use ExpectException; + const LOCATION_ASIA = 'asia-northeast1'; const LOCATION_US = 'US'; const QUERY_TEMPLATE = 'SELECT 1 FROM `%s.%s`'; @@ -31,9 +35,9 @@ class RegionalizationTest extends BigQueryTestCase private static $tableAsia; private static $bucketAsia; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$datasetAsia = self::createDataset( self::$client, uniqid(self::TESTING_PREFIX), @@ -68,11 +72,10 @@ public function testCopyJobSucceedsInAsia() ); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testCopyJobThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $targetTable = self::$datasetAsia ->table(uniqid(self::TESTING_PREFIX)); $copyConfig = self::$tableAsia->copy($targetTable) @@ -95,11 +98,10 @@ public function testExtractJobSucceedsInAsia() $this->assertTrue($object->exists()); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testExtractJobThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $object = self::$bucketAsia->object(uniqid(self::TESTING_PREFIX)); $extractConfig = self::$tableAsia->extract($object) ->destinationFormat('NEWLINE_DELIMITED_JSON') @@ -123,11 +125,10 @@ public function testLoadJobSucceedsInAsia() $this->assertEquals(3, (int) self::$tableAsia->reload()['numRows']); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testLoadJobThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $loadConfig = self::$tableAsia->load( file_get_contents(__DIR__ . '/data/table-data.json') ) @@ -155,11 +156,10 @@ public function testRunQuerySucceedsInAsia() $this->assertEquals(3, (int) $results->info()['totalRows']); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testRunQueryThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $queryConfig = self::$client->query( sprintf( self::QUERY_TEMPLATE, @@ -189,11 +189,10 @@ public function testGetJobSucceedsInAsia() ); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testGetJobThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $queryConfig = self::$client->query( sprintf( self::QUERY_TEMPLATE, @@ -226,11 +225,10 @@ public function testCancelJobSucceedsInAsia() ); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testCancelJobThrowsNotFoundExceptionInUS() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $queryConfig = self::$client->query( sprintf( self::QUERY_TEMPLATE, diff --git a/BigQuery/tests/Unit/BigNumericTest.php b/BigQuery/tests/Unit/BigNumericTest.php index d31b9e73432d..f231a57ae6c5 100644 --- a/BigQuery/tests/Unit/BigNumericTest.php +++ b/BigQuery/tests/Unit/BigNumericTest.php @@ -19,6 +19,7 @@ use Google\Cloud\BigQuery\BigNumeric; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery @@ -26,12 +27,15 @@ */ class BigNumericTest extends TestCase { + use ExpectException; + /** * @dataProvider invalidValueProvider - * @expectedException \InvalidArgumentException */ public function testInvalidValues($value) { + $this->expectException('\InvalidArgumentException'); + new BigNumeric($value); } diff --git a/BigQuery/tests/Unit/BigQueryClientTest.php b/BigQuery/tests/Unit/BigQueryClientTest.php index f3417389c305..50d45e8dbd98 100644 --- a/BigQuery/tests/Unit/BigQueryClientTest.php +++ b/BigQuery/tests/Unit/BigQueryClientTest.php @@ -37,7 +37,7 @@ use Google\Cloud\Core\Int64; use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Core\Upload\AbstractUploader; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -63,7 +63,7 @@ class BigQueryClientTest extends TestCase ] ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/BigQuery/tests/Unit/Connection/RestTest.php b/BigQuery/tests/Unit/Connection/RestTest.php index bb5b5f6a9998..a8013a22f222 100644 --- a/BigQuery/tests/Unit/Connection/RestTest.php +++ b/BigQuery/tests/Unit/Connection/RestTest.php @@ -24,7 +24,7 @@ use Google\Cloud\Core\Upload\AbstractUploader; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -36,7 +36,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/BigQuery/tests/Unit/CopyJobConfigurationTest.php b/BigQuery/tests/Unit/CopyJobConfigurationTest.php index 8ad39c0db4d7..429959b25eac 100644 --- a/BigQuery/tests/Unit/CopyJobConfigurationTest.php +++ b/BigQuery/tests/Unit/CopyJobConfigurationTest.php @@ -19,7 +19,7 @@ use Google\Cloud\BigQuery\CopyJobConfiguration; use Google\Cloud\BigQuery\Table; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -39,7 +39,7 @@ class CopyJobConfigurationTest extends TestCase ]; private $expectedConfig; - public function setUp() + public function set_up() { $this->expectedConfig = [ 'projectId' => self::PROJECT_ID, diff --git a/BigQuery/tests/Unit/DatasetTest.php b/BigQuery/tests/Unit/DatasetTest.php index 8709eb0eaff9..38557c0c6d9a 100644 --- a/BigQuery/tests/Unit/DatasetTest.php +++ b/BigQuery/tests/Unit/DatasetTest.php @@ -26,7 +26,7 @@ use Google\Cloud\Core\Exception\NotFoundException; use Google\Cloud\Core\Iterator\ItemIterator; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -43,7 +43,7 @@ class DatasetTest extends TestCase public $modelId = 'testModelId'; public $routineId = 'testRoutineId'; - public function setUp() + public function set_up() { $this->mapper = new ValueMapper(false); $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/BigQuery/tests/Unit/ExtractJobConfigurationTest.php b/BigQuery/tests/Unit/ExtractJobConfigurationTest.php index 39cd3788821d..7fa8ffdb4fb2 100644 --- a/BigQuery/tests/Unit/ExtractJobConfigurationTest.php +++ b/BigQuery/tests/Unit/ExtractJobConfigurationTest.php @@ -20,7 +20,7 @@ use Google\Cloud\BigQuery\ExtractJobConfiguration; use Google\Cloud\BigQuery\Model; use Google\Cloud\BigQuery\Table; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -49,7 +49,7 @@ class ExtractJobConfigurationTest extends TestCase private $expectedConfig; - public function setUp() + public function set_up() { $this->expectedConfig = [ 'projectId' => self::PROJECT_ID, diff --git a/BigQuery/tests/Unit/JobConfigurationTraitTest.php b/BigQuery/tests/Unit/JobConfigurationTraitTest.php index 1186802d2961..95982ff00946 100644 --- a/BigQuery/tests/Unit/JobConfigurationTraitTest.php +++ b/BigQuery/tests/Unit/JobConfigurationTraitTest.php @@ -19,7 +19,8 @@ use Google\Cloud\BigQuery\JobConfigurationTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; use Ramsey\Uuid\Uuid; /** @@ -27,13 +28,15 @@ */ class JobConfigurationTraitTest extends TestCase { + use AssertIsType; + const PROJECT_ID = 'project-id'; const JOB_ID = '1234'; const LOCATION = 'asia-northeast1'; private $trait; - public function setUp() + public function set_up() { $this->trait = TestHelpers::impl(JobConfigurationTrait::class); } @@ -82,7 +85,7 @@ public function testJobConfigurationPropertiesSetsJobIDWhenNotProvided() ]); $jobId = $this->trait->call('toArray')['jobReference']['jobId']; - $this->assertInternalType('string', $jobId); + $this->assertIsString($jobId); $this->assertTrue(Uuid::isValid($jobId)); } @@ -137,7 +140,7 @@ public function testLocation() public function testGenerateJobId() { $uuid = $this->trait->call('generateJobId'); - $this->assertInternalType('string', $uuid); + $this->assertIsString($uuid); $this->assertTrue(Uuid::isValid($uuid)); } } diff --git a/BigQuery/tests/Unit/JobTest.php b/BigQuery/tests/Unit/JobTest.php index ddfefc617457..3933e178be46 100644 --- a/BigQuery/tests/Unit/JobTest.php +++ b/BigQuery/tests/Unit/JobTest.php @@ -23,7 +23,7 @@ use Google\Cloud\BigQuery\ValueMapper; use Google\Cloud\Core\Exception\NotFoundException; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -36,7 +36,7 @@ class JobTest extends TestCase public $jobId = 'myJobId'; public $jobInfo = ['status' => ['state' => 'DONE']]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/BigQuery/tests/Unit/JobWaitTraitTest.php b/BigQuery/tests/Unit/JobWaitTraitTest.php index 7eba6b80caa4..13bb2fb55272 100644 --- a/BigQuery/tests/Unit/JobWaitTraitTest.php +++ b/BigQuery/tests/Unit/JobWaitTraitTest.php @@ -20,17 +20,20 @@ use Google\Cloud\BigQuery\Job; use Google\Cloud\BigQuery\JobWaitTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery */ class JobWaitTraitTest extends TestCase { + use ExpectException; + private $trait; private $job; - public function setUp() + public function set_up() { $this->trait = TestHelpers::impl(JobWaitTrait::class); $this->job = $this->prophesize(Job::class)->reveal(); @@ -80,12 +83,11 @@ function () use (&$isReloadCalled) { $this->assertTrue($isReloadCalled); } - /** - * @expectedException Google\Cloud\BigQuery\Exception\JobException - * @expectedExceptionMessage Job did not complete within the allowed number of retries. - */ public function testWaitThrowsExceptionWhenMaxAttemptsMet() { + $this->expectException('Google\Cloud\BigQuery\Exception\JobException'); + $this->expectExceptionMessage('Job did not complete within the allowed number of retries.'); + $this->trait->call('wait', [ function () { return false; diff --git a/BigQuery/tests/Unit/LoadJobConfigurationTest.php b/BigQuery/tests/Unit/LoadJobConfigurationTest.php index 1e74f395a8c5..0532205a03e7 100644 --- a/BigQuery/tests/Unit/LoadJobConfigurationTest.php +++ b/BigQuery/tests/Unit/LoadJobConfigurationTest.php @@ -19,7 +19,7 @@ use Google\Cloud\BigQuery\LoadJobConfiguration; use Google\Cloud\BigQuery\Table; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -39,7 +39,7 @@ class LoadJobConfigurationTest extends TestCase ]; private $expectedConfig; - public function setUp() + public function set_up() { $this->expectedConfig = [ 'projectId' => self::PROJECT_ID, diff --git a/BigQuery/tests/Unit/ModelTest.php b/BigQuery/tests/Unit/ModelTest.php index 5de13ed73e74..c97db9af77f1 100644 --- a/BigQuery/tests/Unit/ModelTest.php +++ b/BigQuery/tests/Unit/ModelTest.php @@ -24,7 +24,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Storage\Connection\ConnectionInterface as StorageConnectionInterface; use Google\Cloud\Storage\StorageObject; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -43,7 +43,7 @@ class ModelTest extends TestCase const BUCKET_NAME = 'myBucket'; const FILE_NAME = 'myfile'; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->storageConnection = $this->prophesize(StorageConnectionInterface::class); diff --git a/BigQuery/tests/Unit/NumericTest.php b/BigQuery/tests/Unit/NumericTest.php index 8b4b4904bd4d..dd1583b450e9 100644 --- a/BigQuery/tests/Unit/NumericTest.php +++ b/BigQuery/tests/Unit/NumericTest.php @@ -19,18 +19,22 @@ use Google\Cloud\BigQuery\Numeric; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery */ class NumericTest extends TestCase { + use ExpectException; + /** * @dataProvider invalidValueProvider - * @expectedException \InvalidArgumentException */ public function testInvalidValues($value) { + $this->expectException('\InvalidArgumentException'); + new Numeric($value); } diff --git a/BigQuery/tests/Unit/QueryJobConfigurationTest.php b/BigQuery/tests/Unit/QueryJobConfigurationTest.php index 346b5e010289..b38d473fee45 100644 --- a/BigQuery/tests/Unit/QueryJobConfigurationTest.php +++ b/BigQuery/tests/Unit/QueryJobConfigurationTest.php @@ -21,7 +21,7 @@ use Google\Cloud\BigQuery\QueryJobConfiguration; use Google\Cloud\BigQuery\Table; use Google\Cloud\BigQuery\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigquery @@ -45,7 +45,7 @@ class QueryJobConfigurationTest extends TestCase ]; private $expectedConfig; - public function setUp() + public function set_up() { $this->expectedConfig = [ 'projectId' => self::PROJECT_ID, diff --git a/BigQuery/tests/Unit/QueryResultsTest.php b/BigQuery/tests/Unit/QueryResultsTest.php index 329acca4624b..4e80e7beb7ae 100644 --- a/BigQuery/tests/Unit/QueryResultsTest.php +++ b/BigQuery/tests/Unit/QueryResultsTest.php @@ -23,7 +23,7 @@ use Google\Cloud\BigQuery\QueryResults; use Google\Cloud\BigQuery\ValueMapper; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -54,7 +54,7 @@ class QueryResultsTest extends TestCase ] ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/BigQuery/tests/Unit/RoutineTest.php b/BigQuery/tests/Unit/RoutineTest.php index b3140ffa1802..ee7680fa2d92 100644 --- a/BigQuery/tests/Unit/RoutineTest.php +++ b/BigQuery/tests/Unit/RoutineTest.php @@ -21,7 +21,7 @@ use Google\Cloud\BigQuery\Routine; use Google\Cloud\Core\Exception\NotFoundException; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -42,7 +42,7 @@ class RoutineTest extends TestCase 'projectId' => self::PROJECT_ID ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->routine = TestHelpers::stub(Routine::class, [ diff --git a/BigQuery/tests/Unit/TableTest.php b/BigQuery/tests/Unit/TableTest.php index 98f795eec878..59726ea7aaa7 100644 --- a/BigQuery/tests/Unit/TableTest.php +++ b/BigQuery/tests/Unit/TableTest.php @@ -32,14 +32,17 @@ use Google\Cloud\Core\Upload\AbstractUploader; use Google\Cloud\Storage\Connection\ConnectionInterface as StorageConnectionInterface; use Google\Cloud\Storage\StorageObject; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery */ class TableTest extends TestCase { + use ExpectException; + const JOB_ID = 'myJobId'; const PROJECT_ID = 'myProjectId'; const BUCKET_NAME = 'myBucket'; @@ -74,7 +77,7 @@ class TableTest extends TestCase ] ]; - public function setUp() + public function set_up() { $this->mapper = new ValueMapper(false); $this->connection = $this->prophesize(ConnectionInterface::class); @@ -608,12 +611,11 @@ public function testInsertsRowsWithAutoCreate() $this->assertTrue($insertResponse->isSuccessful()); } - /** - * @expectedException \InvalidArgumentException - * @expectedMessage A schema is required when creating a table. - */ public function testInsertRowsThrowsExceptionWithoutSchema() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('A schema is required when creating a table.'); + $options = [ 'autoCreate' => true ]; @@ -638,11 +640,10 @@ public function testInsertRowsThrowsExceptionWithoutSchema() ], $options); } - /** - * @expectedException \Exception - */ public function testInsertRowsThrowsExceptionWithUnretryableTableFailure() { + $this->expectException('\Exception'); + $options = [ 'autoCreate' => true, 'tableMetadata' => [ @@ -682,11 +683,10 @@ public function testInsertRowsThrowsExceptionWithUnretryableTableFailure() ], $options); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testInsertRowsThrowsExceptionWhenMaxRetryLimitHit() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $options = [ 'autoCreate' => true, 'maxRetries' => 0, @@ -727,22 +727,20 @@ public function testInsertRowsThrowsExceptionWhenMaxRetryLimitHit() ], $options); } - /** - * @expectedException \InvalidArgumentException - * @expectedMessage A row must have a data key. - */ public function testInsertRowsThrowsExceptionWithoutDataKey() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('A row must have a data key.'); + $table = $this->getTable($this->connection); $table->insertRows([[], []]); } - /** - * @expectedException \InvalidArgumentException - * @expectedMessage Must provide at least a single row. - */ public function testInsertRowsThrowsExceptionWithZeroRows() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Must provide at least a single row.'); + $table = $this->getTable($this->connection); $table->insertRows([]); } diff --git a/BigQuery/tests/Unit/ValueMapperTest.php b/BigQuery/tests/Unit/ValueMapperTest.php index af954af56e91..2600dcef6abd 100644 --- a/BigQuery/tests/Unit/ValueMapperTest.php +++ b/BigQuery/tests/Unit/ValueMapperTest.php @@ -26,37 +26,37 @@ use Google\Cloud\BigQuery\ValueMapper; use Google\Cloud\Core\Int64; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigquery */ class ValueMapperTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - */ + use ExpectException; + public function testThrowsExceptionWithUnhandledClass() { + $this->expectException('\InvalidArgumentException'); + $mapper = new ValueMapper(false); $mapper->toParameter(new \stdClass()); } - /** - * @expectedException \InvalidArgumentException - */ public function testToParameterThrowsExceptionWithUnhandledType() { + $this->expectException('\InvalidArgumentException'); + $f = fopen('php://temp', 'r'); fclose($f); $mapper = new ValueMapper(false); $mapper->toParameter($f); } - /** - * @expectedException \InvalidArgumentException - */ public function testFromBigQueryThrowsExceptionWithUnhandledType() { + $this->expectException('\InvalidArgumentException'); + $mapper = new ValueMapper(false); $mapper->fromBigQuery(['v' => 'hi'], ['type' => 'BLAH']); } diff --git a/BigQueryConnection/composer.json b/BigQueryConnection/composer.json index 587eefb05955..77f1da7434a6 100644 --- a/BigQueryConnection/composer.json +++ b/BigQueryConnection/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/BigQueryDataTransfer/composer.json b/BigQueryDataTransfer/composer.json index 1dbea4eb1a82..38fe4d3030bb 100644 --- a/BigQueryDataTransfer/composer.json +++ b/BigQueryDataTransfer/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/BigQueryReservation/composer.json b/BigQueryReservation/composer.json index 8a4334f6ff5c..b5a4a0be7727 100644 --- a/BigQueryReservation/composer.json +++ b/BigQueryReservation/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/BigQueryStorage/composer.json b/BigQueryStorage/composer.json index 73f432b36a91..2fd2159b2665 100644 --- a/BigQueryStorage/composer.json +++ b/BigQueryStorage/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Bigtable/composer.json b/Bigtable/composer.json index 38f32f409d4a..89f35a0815a1 100644 --- a/Bigtable/composer.json +++ b/Bigtable/composer.json @@ -8,9 +8,10 @@ "google/cloud-core": "^1.39" }, "require-dev": { + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "erusev/parsedown": "^1.6", - "phpdocumentor/reflection": "^3.0", - "phpunit/phpunit": "^4.8|^5.0" + "phpdocumentor/reflection": "^3.0" }, "suggest": { "ext-protobuf": "Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions." diff --git a/Bigtable/phpunit-snippets.xml.dist b/Bigtable/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Bigtable/phpunit-snippets.xml.dist +++ b/Bigtable/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Bigtable/tests/Conformance/ReadRowsTest.php b/Bigtable/tests/Conformance/ReadRowsTest.php index 2a9b82af21b3..88559f1118f1 100644 --- a/Bigtable/tests/Conformance/ReadRowsTest.php +++ b/Bigtable/tests/Conformance/ReadRowsTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Bigtable\Exception\BigtableDataOperationException; use Google\Cloud\Bigtable\V2\ReadRowsResponse; use Google\Cloud\Bigtable\V2\ReadRowsResponse_CellChunk; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -32,7 +32,7 @@ class ReadRowsTest extends TestCase { private $serverStream; - public function setUp() + public function set_up() { $this->serverStream = $this->prophesize(ServerStream::class); } diff --git a/Bigtable/tests/Snippet/ChunkFormatterTest.php b/Bigtable/tests/Snippet/ChunkFormatterTest.php index 1734d1cc2dac..1a97c7eca550 100644 --- a/Bigtable/tests/Snippet/ChunkFormatterTest.php +++ b/Bigtable/tests/Snippet/ChunkFormatterTest.php @@ -36,7 +36,7 @@ class ChunkFormatterTest extends SnippetTestCase private $table; private $serverStream; - public function setUp() + public function set_up() { $this->bigtableClient = $this->prophesize(TableClient::class); $this->serverStream = $this->prophesize(ServerStream::class); diff --git a/Bigtable/tests/Snippet/Filter/Builder/FamilyFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/FamilyFilterTest.php index d6ccee5ea13a..1f6bf9899f51 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/FamilyFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/FamilyFilterTest.php @@ -30,7 +30,7 @@ class FamilyFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::family(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/KeyFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/KeyFilterTest.php index 96dd5831b563..86652db16766 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/KeyFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/KeyFilterTest.php @@ -30,7 +30,7 @@ class KeyFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::key(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/LimitFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/LimitFilterTest.php index bbdffa4346e0..cebdd90a4388 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/LimitFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/LimitFilterTest.php @@ -30,7 +30,7 @@ class LimitFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::limit(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/OffsetFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/OffsetFilterTest.php index 95546cb02e15..0630989b8664 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/OffsetFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/OffsetFilterTest.php @@ -30,7 +30,7 @@ class OffsetFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::offset(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/QualifierFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/QualifierFilterTest.php index 93091c11faca..59fd2cb85f55 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/QualifierFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/QualifierFilterTest.php @@ -31,7 +31,7 @@ class QualifierFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::qualifier(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/TimestampFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/TimestampFilterTest.php index 457a4bd346cd..d8bcf99f33d1 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/TimestampFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/TimestampFilterTest.php @@ -32,7 +32,7 @@ class TimestampFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::timestamp(); } diff --git a/Bigtable/tests/Snippet/Filter/Builder/ValueFilterTest.php b/Bigtable/tests/Snippet/Filter/Builder/ValueFilterTest.php index 4ef8546d30e8..0d35b324a4d1 100644 --- a/Bigtable/tests/Snippet/Filter/Builder/ValueFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/Builder/ValueFilterTest.php @@ -31,7 +31,7 @@ class ValueFilterTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = Filter::value(); } diff --git a/Bigtable/tests/Snippet/Filter/ChainFilterTest.php b/Bigtable/tests/Snippet/Filter/ChainFilterTest.php index 26a312c8fc85..2b030135df8b 100644 --- a/Bigtable/tests/Snippet/Filter/ChainFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/ChainFilterTest.php @@ -31,7 +31,7 @@ class ChainFilterTest extends SnippetTestCase { private $chainFilter; - public function setUp() + public function set_up() { $this->chainFilter = Filter::chain(); } diff --git a/Bigtable/tests/Snippet/Filter/ConditionFilterTest.php b/Bigtable/tests/Snippet/Filter/ConditionFilterTest.php index 1f7d80fb6ac5..7aeb959b6441 100644 --- a/Bigtable/tests/Snippet/Filter/ConditionFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/ConditionFilterTest.php @@ -31,7 +31,7 @@ class ConditionFilterTest extends SnippetTestCase { private $conditionFilter; - public function setUp() + public function set_up() { $this->conditionFilter = Filter::condition(Filter::key()->regex('prefix.*')); } diff --git a/Bigtable/tests/Snippet/Filter/InterleaveFilterTest.php b/Bigtable/tests/Snippet/Filter/InterleaveFilterTest.php index 3df6c3bba44e..86e8f5900504 100644 --- a/Bigtable/tests/Snippet/Filter/InterleaveFilterTest.php +++ b/Bigtable/tests/Snippet/Filter/InterleaveFilterTest.php @@ -31,7 +31,7 @@ class InterleaveFilterTest extends SnippetTestCase { private $interleaveFilter; - public function setUp() + public function set_up() { $this->interleaveFilter = Filter::interleave(); } diff --git a/Bigtable/tests/Snippet/TableTest.php b/Bigtable/tests/Snippet/TableTest.php index 68614c3b6dfc..9ec54399d1a4 100644 --- a/Bigtable/tests/Snippet/TableTest.php +++ b/Bigtable/tests/Snippet/TableTest.php @@ -62,7 +62,7 @@ class TableTest extends SnippetTestCase private $serverStream; private $entries = []; - public function setUp() + public function set_up() { $this->bigtableClient = $this->prophesize(TableClient::class); $this->serverStream = $this->prophesize(ServerStream::class); diff --git a/Bigtable/tests/System/BigtableInstanceAdminClientTest.php b/Bigtable/tests/System/BigtableInstanceAdminClientTest.php index cd2ad3db2ca2..3a49166aa382 100644 --- a/Bigtable/tests/System/BigtableInstanceAdminClientTest.php +++ b/Bigtable/tests/System/BigtableInstanceAdminClientTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; use Google\Cloud\Bigtable\Admin\V2\ListInstancesResponse; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class BigtableInstanceAdminClientTest extends TestCase { @@ -30,7 +30,7 @@ class BigtableInstanceAdminClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -38,7 +38,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Bigtable/tests/System/BigtableTestCase.php b/Bigtable/tests/System/BigtableTestCase.php index 8e60a44955c0..1f01058acbc4 100644 --- a/Bigtable/tests/System/BigtableTestCase.php +++ b/Bigtable/tests/System/BigtableTestCase.php @@ -45,7 +45,7 @@ class BigtableTestCase extends SystemTestCase protected static $instanceId; protected static $clusterId; - public static function setUpBeforeClass() + public static function set_up_before_class() { self::setUsingEmulator(getenv('BIGTABLE_EMULATOR_HOST')); $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); @@ -69,7 +69,7 @@ public static function setUpBeforeClass() self::createTable(); } - public static function tearDownAfterClass() + public static function tear_down_after_class() { self::deleteTable(); if (!self::isEmulatorUsed()) { diff --git a/Bigtable/tests/System/CheckAndMutateRowTest.php b/Bigtable/tests/System/CheckAndMutateRowTest.php index 83dec33a6716..48dbc683e595 100644 --- a/Bigtable/tests/System/CheckAndMutateRowTest.php +++ b/Bigtable/tests/System/CheckAndMutateRowTest.php @@ -26,9 +26,9 @@ */ class CheckAndMutateRowTest extends BigtableTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/FilterTest.php b/Bigtable/tests/System/FilterTest.php index ad51d43e3c9a..e358a231b7cd 100644 --- a/Bigtable/tests/System/FilterTest.php +++ b/Bigtable/tests/System/FilterTest.php @@ -28,9 +28,9 @@ class FilterTest extends BigtableTestCase { protected static $rowMutations = []; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$table->mutateRows(self::$rowMutations); } diff --git a/Bigtable/tests/System/ReadModifyWriteRowTest.php b/Bigtable/tests/System/ReadModifyWriteRowTest.php index 0942e9788f0c..611dc75b5e9b 100644 --- a/Bigtable/tests/System/ReadModifyWriteRowTest.php +++ b/Bigtable/tests/System/ReadModifyWriteRowTest.php @@ -26,9 +26,9 @@ */ class ReadModifyWriteRowTest extends BigtableTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/ReadRowsTest.php b/Bigtable/tests/System/ReadRowsTest.php index 17aecb4fe988..545c4d524ddc 100644 --- a/Bigtable/tests/System/ReadRowsTest.php +++ b/Bigtable/tests/System/ReadRowsTest.php @@ -23,9 +23,9 @@ */ class ReadRowsTest extends BigtableTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/SampleRowKeysTest.php b/Bigtable/tests/System/SampleRowKeysTest.php index e7ccd0af20e6..f547b0dec035 100644 --- a/Bigtable/tests/System/SampleRowKeysTest.php +++ b/Bigtable/tests/System/SampleRowKeysTest.php @@ -23,9 +23,9 @@ */ class SampleRowKeysTest extends BigtableTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/Unit/BigtableClientTest.php b/Bigtable/tests/Unit/BigtableClientTest.php index 37fc7df4a58c..dbb3afb46e31 100644 --- a/Bigtable/tests/Unit/BigtableClientTest.php +++ b/Bigtable/tests/Unit/BigtableClientTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\BigtableClient; use Google\Cloud\Bigtable\Table; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -30,7 +30,7 @@ class BigtableClientTest extends TestCase { private $client; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(BigtableClient::class, [ ['projectId' => 'my-project'] diff --git a/Bigtable/tests/Unit/ChunkFormatterTest.php b/Bigtable/tests/Unit/ChunkFormatterTest.php index b7008048f579..dce1455f6538 100644 --- a/Bigtable/tests/Unit/ChunkFormatterTest.php +++ b/Bigtable/tests/Unit/ChunkFormatterTest.php @@ -23,7 +23,8 @@ use Google\Cloud\Bigtable\V2\ReadRowsResponse\CellChunk as ReadRowsResponse_CellChunk; use Google\Protobuf\StringValue; use Google\Protobuf\BytesValue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -31,11 +32,13 @@ */ class ChunkFormatterTest extends TestCase { + use ExpectException; + const TABLE_NAME = 'test-table'; private $serverStream; private $chunkFormatter; - public function setUp() + public function set_up() { $this->serverStream = $this->prophesize(ServerStream::class); $this->chunkFormatter = new ChunkFormatter( @@ -47,12 +50,11 @@ function () { ); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A row key must be set. - */ public function testNewRowShouldThrowWhenNoRowKey() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A row key must be set.'); + $readRowsResponse = new ReadRowsResponse; $chunk = new ReadRowsResponse_CellChunk(); $readRowsResponse->setChunks([$chunk]); @@ -95,12 +97,11 @@ public function testNewRowShouldGenerateWhenRowKeyIsZero() $this->assertEquals($expectedRows, $rows); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A new row cannot be reset. - */ public function testNewRowShouldThrowWhenResetIsTrue() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A new row cannot be reset.'); + $readRowsResponse = new ReadRowsResponse; $chunk = new ReadRowsResponse_CellChunk(); $chunk->setRowKey('rk1'); @@ -112,12 +113,11 @@ public function testNewRowShouldThrowWhenResetIsTrue() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A family must be set. - */ public function testNewRowShouldThrowWhenNoFamilyName() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A family must be set.'); + $readRowsResponse = new ReadRowsResponse; $chunk = new ReadRowsResponse_CellChunk(); $chunk->setRowKey('rk1'); @@ -128,12 +128,11 @@ public function testNewRowShouldThrowWhenNoFamilyName() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A column qualifier must be set. - */ public function testNewRowShouldThrowWhenNoQualifier() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A column qualifier must be set.'); + $readRowsResponse = new ReadRowsResponse; $chunk = new ReadRowsResponse_CellChunk(); $chunk->setRowKey('rk1'); @@ -147,12 +146,11 @@ public function testNewRowShouldThrowWhenNoQualifier() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A row cannot have a value size and be a commit row. - */ public function testNewRowShouldThrowWhenValueSizeAndCommitRow() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A row cannot have a value size and be a commit row.'); + $readRowsResponse = new ReadRowsResponse; $chunk = new ReadRowsResponse_CellChunk(); $chunk->setRowKey('rk1'); @@ -171,12 +169,11 @@ public function testNewRowShouldThrowWhenValueSizeAndCommitRow() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A commit happened but the same key followed. - */ public function testNewRowShouldThrowWhenSameRowKeyFollows() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A commit happened but the same key followed.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -381,12 +378,11 @@ public function testNewRowShouldGenerateNewRowWithLabels() $this->assertEquals($expectedRows, $rows); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage Response ended with pending row without commit. - */ public function testNewRowShouldThrowWhenPendingRow() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('Response ended with pending row without commit.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -406,12 +402,11 @@ public function testNewRowShouldThrowWhenPendingRow() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testValidateResetWithRowKey() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -435,12 +430,11 @@ public function testValidateResetWithRowKey() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testValidateResetWithQualifier() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -464,12 +458,11 @@ public function testValidateResetWithQualifier() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testValidateResetWithValue() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -493,12 +486,11 @@ public function testValidateResetWithValue() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testValidateResetWithTimestampMicro() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -522,12 +514,11 @@ public function testValidateResetWithTimestampMicro() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A commit is required between row keys. - */ public function testRowInProgressDifferentRowKey() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A commit is required between row keys.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -550,12 +541,11 @@ public function testRowInProgressDifferentRowKey() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A qualifier must be specified. - */ public function testRowInProgressFamilyNameWithouQualifier() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A qualifier must be specified.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -581,12 +571,11 @@ public function testRowInProgressFamilyNameWithouQualifier() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A row cannot have a value size and be a commit row. - */ public function testRowInProgressValueSizeAndCommit() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A row cannot have a value size and be a commit row.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -829,12 +818,11 @@ public function testRowInProgressWithLabels() $this->assertEquals($expectedRows, $rows); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A row cannot have a value size and be a commit row. - */ public function testCellInProgressValueSizeAndCommit() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A row cannot have a value size and be a commit row.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -859,12 +847,11 @@ public function testCellInProgressValueSizeAndCommit() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testCellInProgressValidateResetWithRowKey() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -889,12 +876,11 @@ public function testCellInProgressValidateResetWithRowKey() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testCellInProgressValidateResetWithQualifier() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -921,12 +907,11 @@ public function testCellInProgressValidateResetWithQualifier() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testCellInProgressValidateResetWithValue() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); @@ -951,12 +936,11 @@ public function testCellInProgressValidateResetWithValue() iterator_to_array($this->chunkFormatter->readAll()); } - /** - * @expectedException \Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage A reset should have no data. - */ public function testCellInProgressValidateResetWithTimestampMicro() { + $this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('A reset should have no data.'); + $readRowsResponse = new ReadRowsResponse; $chunks = []; $chunk = new ReadRowsResponse_CellChunk(); diff --git a/Bigtable/tests/Unit/DataUtilTest.php b/Bigtable/tests/Unit/DataUtilTest.php index 59a38af3e6f4..74d83f6f56a9 100644 --- a/Bigtable/tests/Unit/DataUtilTest.php +++ b/Bigtable/tests/Unit/DataUtilTest.php @@ -18,7 +18,8 @@ namespace Google\Cloud\Bigtable\Tests\Unit; use Google\Cloud\Bigtable\DataUtil; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -26,19 +27,20 @@ */ class DataUtilTest extends TestCase { - public function setUp() + use ExpectException; + + public function set_up() { if (!DataUtil::isSupported()) { $this->markTestSkipped('Tested functionality is not supported in the current version of PHP.'); } } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Expected argument to be of type int, instead got - */ public function testIntToByteStringThrowsExceptionWithoutInteger() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Expected argument to be of type int, instead got'); + DataUtil::intToByteString('abc'); } diff --git a/Bigtable/tests/Unit/Filter/Builder/FamilyFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/FamilyFilterTest.php index 123aa7aa9bdb..604b50600532 100644 --- a/Bigtable/tests/Unit/Filter/Builder/FamilyFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/FamilyFilterTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\Filter\Builder\FamilyFilter; use Google\Cloud\Bigtable\Filter\SimpleFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -30,7 +30,7 @@ class FamilyFilterTest extends TestCase { private $familyFilter; - public function setUp() + public function set_up() { $this->familyFilter = new FamilyFilter; } diff --git a/Bigtable/tests/Unit/Filter/Builder/KeyFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/KeyFilterTest.php index c7c5080394ee..751d9d55e173 100644 --- a/Bigtable/tests/Unit/Filter/Builder/KeyFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/KeyFilterTest.php @@ -20,7 +20,8 @@ use Google\Cloud\Bigtable\Filter\Builder\KeyFilter; use Google\Cloud\Bigtable\Filter\SimpleFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -28,9 +29,11 @@ */ class KeyFilterTest extends TestCase { + use ExpectException; + private $keyFilter; - public function setUp() + public function set_up() { $this->keyFilter = new KeyFilter; } @@ -53,21 +56,19 @@ public function testExactMatch() $this->assertEquals($rowFilter, $filter->toProto()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Probability must be positive - */ public function testSampleShouldThrowOnLessThanZero() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Probability must be positive'); + $this->keyFilter->sample(-1); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Probability must be less than 1.0 - */ public function testSampleShouldThrowOnGreaterThanOne() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Probability must be less than 1.0'); + $this->keyFilter->sample(1.1); } diff --git a/Bigtable/tests/Unit/Filter/Builder/LimitFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/LimitFilterTest.php index e2fef4e762cf..dd347206173b 100644 --- a/Bigtable/tests/Unit/Filter/Builder/LimitFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/LimitFilterTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Filter\Builder\LimitFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -30,7 +30,7 @@ class LimitFilterTest extends TestCase { private $limitFilter; - public function setUp() + public function set_up() { $this->limitFilter = Filter::limit(); } diff --git a/Bigtable/tests/Unit/Filter/Builder/OffsetFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/OffsetFilterTest.php index f4279ba9969a..1529c22fcb3e 100644 --- a/Bigtable/tests/Unit/Filter/Builder/OffsetFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/OffsetFilterTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Filter\Builder\OffsetFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -30,7 +30,7 @@ class OffsetFilterTest extends TestCase { private $offsetFilter; - public function setUp() + public function set_up() { $this->offsetFilter = Filter::offset(); } diff --git a/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php index 8725d5a0a962..556fee35dee6 100644 --- a/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\QualifierRangeFilter; use Google\Cloud\Bigtable\Filter\SimpleFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -31,7 +31,7 @@ class QualifierFilterTest extends TestCase { private $qualifierFilter; - public function setUp() + public function set_up() { $this->qualifierFilter = new QualifierFilter; } diff --git a/Bigtable/tests/Unit/Filter/Builder/RangeTest.php b/Bigtable/tests/Unit/Filter/Builder/RangeTest.php index 11b8eb68974d..401e059218fb 100644 --- a/Bigtable/tests/Unit/Filter/Builder/RangeTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/RangeTest.php @@ -19,7 +19,8 @@ use Google\Cloud\Bigtable\Filter\Builder\Range; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -27,9 +28,11 @@ */ class RangeTest extends TestCase { + use ExpectException; + private $range; - public function setUp() + public function set_up() { $this->range = TestHelpers::stub(Range::class); } @@ -41,21 +44,19 @@ public function testClass() $this->assertEquals(Range::BOUND_TYPE_UNBOUNDED, $this->range->getEndBound()); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Start is unbounded - */ public function testGetStartShouldThrow() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Start is unbounded'); + $this->range->getStart(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage End is unbounded - */ public function testGetEndShouldThrow() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('End is unbounded'); + $this->range->getEnd(); } @@ -66,21 +67,19 @@ public function testStartUnbounded() $this->assertEquals(Range::BOUND_TYPE_UNBOUNDED, $this->range->getStartBound()); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Start is unbounded - */ public function testStartUnboundedShouldThrowOnGetStart() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Start is unbounded'); + $this->range->startUnbounded()->getStart(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage startOpen accepts only string or numeric types. - */ public function testStartOpenShouldThrow() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('startOpen accepts only string or numeric types.'); + $this->range->startOpen(null); } @@ -92,12 +91,11 @@ public function testStartOpen() $this->assertEquals('so1', $range->getStart()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage startClosed accepts only string or numeric types. - */ public function testStartClosedShouldThrow() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('startClosed accepts only string or numeric types.'); + $this->range->startClosed(null); } @@ -116,21 +114,19 @@ public function testEndUnbounded() $this->assertEquals(Range::BOUND_TYPE_UNBOUNDED, $range->getEndBound()); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage End is unbounded - */ public function testEndUnboundedShouldThrow() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('End is unbounded'); + $this->range->endUnbounded()->getEnd(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage endOpen accepts only string or numeric types. - */ public function testEndOpenShouldThrow() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('endOpen accepts only string or numeric types.'); + $this->range->endOpen(null); } @@ -142,12 +138,11 @@ public function testEndOpen() $this->assertEquals('eo1', $range->getEnd()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage endClosed accepts only string or numeric types. - */ public function testEndClosedShouldThrow() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('endClosed accepts only string or numeric types.'); + $this->range->endClosed(null); } diff --git a/Bigtable/tests/Unit/Filter/Builder/RegexTraitTest.php b/Bigtable/tests/Unit/Filter/Builder/RegexTraitTest.php index 477bf13fbb2b..df05c463c96f 100644 --- a/Bigtable/tests/Unit/Filter/Builder/RegexTraitTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/RegexTraitTest.php @@ -19,7 +19,8 @@ use Google\Cloud\Bigtable\Filter\Builder\RegexTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -27,9 +28,11 @@ */ class RegexTraitTest extends TestCase { + use ExpectException; + private $implementation; - public function setUp() + public function set_up() { $this->implementation = TestHelpers::impl(RegexTrait::class); } @@ -42,12 +45,11 @@ public function testEscapeLiteralValueShouldReturnNullOnNull() ); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Expected byte array or string, instead got 'object'. - */ public function testEscapeLiteralValueShouldThrowIfNotByteArrayOrString() { + $this->expectException('\Exception'); + $this->expectExceptionMessage('Expected byte array or string, instead got \'object\'.'); + $this->implementation->call('escapeLiteralValue', [new \stdClass]); } diff --git a/Bigtable/tests/Unit/Filter/Builder/ValueFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/ValueFilterTest.php index c1693e325ed6..15c2556a0324 100644 --- a/Bigtable/tests/Unit/Filter/Builder/ValueFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/ValueFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\Builder\ValueFilter; use Google\Cloud\Bigtable\Filter\ValueRangeFilter; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -31,7 +31,7 @@ class ValueFilterTest extends TestCase { private $valueFilter; - public function setUp() + public function set_up() { $this->valueFilter = new ValueFilter; } diff --git a/Bigtable/tests/Unit/Filter/ChainFilterTest.php b/Bigtable/tests/Unit/Filter/ChainFilterTest.php index 1a58ac968e55..53c55b9fe549 100644 --- a/Bigtable/tests/Unit/Filter/ChainFilterTest.php +++ b/Bigtable/tests/Unit/Filter/ChainFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\ChainFilter; use Google\Cloud\Bigtable\V2\RowFilter; use Google\Cloud\Bigtable\V2\RowFilter\Chain; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -31,7 +31,7 @@ class ChainFilterTest extends TestCase { private $chainFilter; - public function setUp() + public function set_up() { $this->chainFilter = new ChainFilter; } diff --git a/Bigtable/tests/Unit/Filter/ConditionFilterTest.php b/Bigtable/tests/Unit/Filter/ConditionFilterTest.php index 77b101390569..5eff9755b6f2 100644 --- a/Bigtable/tests/Unit/Filter/ConditionFilterTest.php +++ b/Bigtable/tests/Unit/Filter/ConditionFilterTest.php @@ -21,7 +21,8 @@ use Google\Cloud\Bigtable\Filter\ConditionFilter; use Google\Cloud\Bigtable\V2\RowFilter; use Google\Cloud\Bigtable\V2\RowFilter\Condition; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -29,10 +30,12 @@ */ class ConditionFilterTest extends TestCase { + use ExpectException; + private $conditionFilter; private $condition; - public function setUp() + public function set_up() { $this->conditionFilter = new ConditionFilter(Filter::pass()); $this->condition = new Condition(); @@ -40,14 +43,15 @@ public function setUp() } /** - * @expectedException \RuntimeException - * @expectedExceptionMessage In order to utilize a condition filter you must * supply a filter through either * Google\Cloud\Bigtable\Filter\ConditionFilter:then() * or Google\Cloud\Bigtable\Filter\ConditionFilter:otherwise(). */ public function testPredicate() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('In order to utilize a condition filter you must'); + $this->conditionFilter->toProto(); } diff --git a/Bigtable/tests/Unit/Filter/InterleaveFilterTest.php b/Bigtable/tests/Unit/Filter/InterleaveFilterTest.php index 0031c0b58503..7ce920348357 100644 --- a/Bigtable/tests/Unit/Filter/InterleaveFilterTest.php +++ b/Bigtable/tests/Unit/Filter/InterleaveFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\InterleaveFilter; use Google\Cloud\Bigtable\V2\RowFilter; use Google\Cloud\Bigtable\V2\RowFilter\Interleave; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -31,7 +31,7 @@ class InterleaveFilterTest extends TestCase { private $interleaveFilter; - public function setUp() + public function set_up() { $this->interleaveFilter = new InterleaveFilter; } diff --git a/Bigtable/tests/Unit/Filter/QualifierRangeFilterTest.php b/Bigtable/tests/Unit/Filter/QualifierRangeFilterTest.php index 25cce7084e3e..934375ddc316 100644 --- a/Bigtable/tests/Unit/Filter/QualifierRangeFilterTest.php +++ b/Bigtable/tests/Unit/Filter/QualifierRangeFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\QualifierRangeFilter; use Google\Cloud\Bigtable\V2\ColumnRange; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -33,7 +33,7 @@ class QualifierRangeFilterTest extends TestCase private $qualifierRangeFilter; - public function setUp() + public function set_up() { $this->qualifierRangeFilter = Filter::qualifier()->rangeWithInFamily(self::FAMILY_NAME); } diff --git a/Bigtable/tests/Unit/Filter/TimestampRangeFilterTest.php b/Bigtable/tests/Unit/Filter/TimestampRangeFilterTest.php index 7a973e6f7264..c3ea81a64b77 100644 --- a/Bigtable/tests/Unit/Filter/TimestampRangeFilterTest.php +++ b/Bigtable/tests/Unit/Filter/TimestampRangeFilterTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\Filter\TimestampRangeFilter; use Google\Cloud\Bigtable\V2\TimestampRange; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -30,7 +30,7 @@ class TimestampRangeFilterTest extends TestCase { private $timestampRangeFilter; - public function setUp() + public function set_up() { $this->timestampRangeFilter = new TimestampRangeFilter(); } diff --git a/Bigtable/tests/Unit/Filter/ValueRangeFilterTest.php b/Bigtable/tests/Unit/Filter/ValueRangeFilterTest.php index d1caab74f0cd..63685fd0b25f 100644 --- a/Bigtable/tests/Unit/Filter/ValueRangeFilterTest.php +++ b/Bigtable/tests/Unit/Filter/ValueRangeFilterTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Bigtable\Filter\ValueRangeFilter; use Google\Cloud\Bigtable\V2\ValueRange; use Google\Cloud\Bigtable\V2\RowFilter; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -31,7 +31,7 @@ class ValueRangeFilterTest extends TestCase { private $valueRangeFilter; - public function setUp() + public function set_up() { $this->valueRangeFilter = new ValueRangeFilter(); } diff --git a/Bigtable/tests/Unit/MutationsTest.php b/Bigtable/tests/Unit/MutationsTest.php index 8211527b4edc..8b656140f07d 100644 --- a/Bigtable/tests/Unit/MutationsTest.php +++ b/Bigtable/tests/Unit/MutationsTest.php @@ -24,7 +24,7 @@ use Google\Cloud\Bigtable\V2\Mutation\DeleteFromRow; use Google\Cloud\Bigtable\V2\Mutation\SetCell; use Google\Cloud\Bigtable\V2\TimestampRange; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -39,7 +39,7 @@ class MutationsTest extends TestCase private $mutations; - public function setUp() + public function set_up() { $this->mutations = new MutationsStub; } diff --git a/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php b/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php index 11fc1f1bd1e0..c3fbbce42870 100644 --- a/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php +++ b/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group bigtable @@ -32,7 +32,7 @@ class ReadModifyWriteRowRulesTest extends TestCase private $readModifyWriteRowRules; - public function setUp() + public function set_up() { $this->readModifyWriteRowRules = new ReadModifyWriteRowRules; } diff --git a/Bigtable/tests/Unit/SmartRetriesTest.php b/Bigtable/tests/Unit/SmartRetriesTest.php index 50392da31ce2..72c669f4db62 100644 --- a/Bigtable/tests/Unit/SmartRetriesTest.php +++ b/Bigtable/tests/Unit/SmartRetriesTest.php @@ -34,7 +34,8 @@ use Google\Protobuf\BytesValue; use Google\Rpc\Code; use Google\Rpc\Status; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -43,6 +44,8 @@ */ class SmartRetriesTest extends TestCase { + use ExpectException; + const HEADER = 'my-header'; const HEADER_VALUE = 'my-header-value'; const APP_PROFILE = 'my-app-profile'; @@ -56,7 +59,7 @@ class SmartRetriesTest extends TestCase private $retryingApiException; private $nonRetryingApiException; - public function setUp() + public function set_up() { $this->retryingApiException = new ApiException( 'DEADLINE_EXCEEDED', @@ -81,12 +84,11 @@ public function setUp() ); } - /** - * @expectedException Google\ApiCore\ApiException - * @expectedExceptionMessage DEADLINE_EXCEEDED - */ public function testReadRowsShouldRetryDefaultTimes() { + $this->expectException('Google\ApiCore\ApiException'); + $this->expectExceptionMessage('DEADLINE_EXCEEDED'); + $expectedArgs = $this->options; $this->serverStream->readAll() ->shouldBeCalledTimes(4) @@ -103,12 +105,11 @@ public function testReadRowsShouldRetryDefaultTimes() $iterator->getIterator()->current(); } - /** - * @expectedException Google\ApiCore\ApiException - * @expectedExceptionMessage DEADLINE_EXCEEDED - */ public function testReadRowsShouldRetryForProvidedAttempts() { + $this->expectException('Google\ApiCore\ApiException'); + $this->expectExceptionMessage('DEADLINE_EXCEEDED'); + $expectedArgs = $this->options; $this->serverStream->readAll() ->shouldBeCalledTimes(6) @@ -450,12 +451,11 @@ public function testReadRowsRangeWithSomeCompletedRange() $this->assertEquals($expectedRows, $rows); } - /** - * @expectedException Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage DEADLINE_EXCEEDED - */ public function testMutateRowsShouldRetryDefaultNumberOfTimes() { + $this->expectException('Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('DEADLINE_EXCEEDED'); + $this->serverStream->readAll() ->shouldBeCalledTimes(4) ->willThrow( @@ -471,12 +471,11 @@ public function testMutateRowsShouldRetryDefaultNumberOfTimes() $this->table->mutateRows($mutations); } - /** - * @expectedException Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage DEADLINE_EXCEEDED - */ public function testMutateRowsRespectRetriesAttempt() { + $this->expectException('Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('DEADLINE_EXCEEDED'); + $this->serverStream->readAll() ->shouldBeCalledTimes(6) ->willThrow( diff --git a/Bigtable/tests/Unit/TableTest.php b/Bigtable/tests/Unit/TableTest.php index e3dc3df5ebd3..972d6da0797a 100644 --- a/Bigtable/tests/Unit/TableTest.php +++ b/Bigtable/tests/Unit/TableTest.php @@ -42,7 +42,8 @@ use Google\Cloud\Bigtable\V2\SampleRowKeysResponse; use Google\Rpc\Code; use Google\Rpc\Status; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group bigtable @@ -50,6 +51,8 @@ */ class TableTest extends TestCase { + use ExpectException; + const HEADER = 'my-header'; const HEADER_VALUE = 'my-header-value'; const APP_PROFILE = 'my-app-profile'; @@ -63,7 +66,7 @@ class TableTest extends TestCase private $options; private $serverStream; - public function setUp() + public function set_up() { $this->bigtableClient = $this->prophesize(TableClient::class); $this->serverStream = $this->prophesize(ServerStream::class); @@ -91,12 +94,11 @@ public function setUp() $this->rowMutations['rk2'] = $mutations; } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Expected rowMutations to be of type associative array, instead got list. - */ public function testMutateRowsThrowsExceptionWhenRowMutationsIsList() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Expected rowMutations to be of type associative array, instead got list.'); + $this->table->mutateRows([1,2,3,4]); } @@ -182,12 +184,11 @@ public function testMutateRowsFailure() } } - /** - * @expectedException Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage unauthenticated - */ public function testMutateRowsApiExceptionInMutateRows() { + $this->expectException('Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('unauthenticated'); + $apiException = new ApiException('unauthenticated', Code::UNAUTHENTICATED, 'unauthenticated'); $this->bigtableClient->mutateRows(self::TABLE_NAME, $this->entries, $this->options) ->shouldBeCalled() @@ -197,12 +198,11 @@ public function testMutateRowsApiExceptionInMutateRows() $this->table->mutateRows($this->rowMutations); } - /** - * @expectedException Google\Cloud\Bigtable\Exception\BigtableDataOperationException - * @expectedExceptionMessage unauthenticated - */ public function testMutateRowsApiExceptionInReadAll() { + $this->expectException('Google\Cloud\Bigtable\Exception\BigtableDataOperationException'); + $this->expectExceptionMessage('unauthenticated'); + $apiException = new ApiException('unauthenticated', Code::UNAUTHENTICATED, 'unauthenticated'); $this->serverStream->readAll() ->shouldBeCalled() @@ -783,39 +783,35 @@ public function testSampleRowKeys() $this->assertEquals($expectedRowKeys, $rowKeys); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage checkAndMutateRow must have either trueMutations or falseMutations. - */ public function testCheckAndMutateRowShouldThrowWhenNoTrueOrFalseMutations() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('checkAndMutateRow must have either trueMutations or falseMutations.'); + $this->table->checkAndMutateRow('rk1'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage FilterInterface - */ public function testCheckAndMutateRowShouldThrowWhenPredicateFilterIsNotFilter() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('FilterInterface'); + $this->table->checkAndMutateRow('rk1', ['predicateFilter' => new \stdClass()]); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Mutations - */ public function testCheckAndMutateRowShouldThrowWhenTrueMutationsNotMutations() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Mutations'); + $this->table->checkAndMutateRow('rk1', ['trueMutations' => new \stdClass()]); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Mutations - */ public function testCheckAndMutateRowShouldThrowWhenFalseMutationsNotMutations() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Mutations'); + $this->table->checkAndMutateRow('rk1', ['falseMutations' => new \stdClass()]); } diff --git a/Billing/composer.json b/Billing/composer.json index f0a929542e41..78066533b920 100644 --- a/Billing/composer.json +++ b/Billing/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/BillingBudgets/composer.json b/BillingBudgets/composer.json index 450144a8f707..11a74148fbd1 100644 --- a/BillingBudgets/composer.json +++ b/BillingBudgets/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/BinaryAuthorization/composer.json b/BinaryAuthorization/composer.json index 358e2e29e98b..2bdbdcfcc823 100644 --- a/BinaryAuthorization/composer.json +++ b/BinaryAuthorization/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Build/composer.json b/Build/composer.json index 2c9372eec3fd..9d00802a86ef 100644 --- a/Build/composer.json +++ b/Build/composer.json @@ -27,7 +27,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/CertificateManager/composer.json b/CertificateManager/composer.json index 9f5645a6cfaa..68a070ebcd0d 100644 --- a/CertificateManager/composer.json +++ b/CertificateManager/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Channel/composer.json b/Channel/composer.json index ba3d3b370055..4a07eb8c71b6 100644 --- a/Channel/composer.json +++ b/Channel/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Compute/composer.json b/Compute/composer.json index 80be4b5d8252..7e207cf50c85 100644 --- a/Compute/composer.json +++ b/Compute/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.9" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Compute/tests/System/V1/SmokeTest.php b/Compute/tests/System/V1/SmokeTest.php index 988a41636d78..7bc1c8b31be0 100644 --- a/Compute/tests/System/V1/SmokeTest.php +++ b/Compute/tests/System/V1/SmokeTest.php @@ -31,6 +31,7 @@ use Google\Cloud\Compute\V1\ZoneOperationsClient; use Google\Cloud\Compute\V1\ShieldedInstanceConfig; use Google\Cloud\Core\Testing\System\SystemTestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group compute @@ -38,6 +39,8 @@ */ class SmokeTest extends SystemTestCase { + use ExpectException; + const ZONE = 'us-central1-a'; const IMAGE = 'projects/debian-cloud/global/images/family/debian-10'; diff --git a/ContactCenterInsights/composer.json b/ContactCenterInsights/composer.json index 29fad7926e3c..33487b64e3cd 100644 --- a/ContactCenterInsights/composer.json +++ b/ContactCenterInsights/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Container/composer.json b/Container/composer.json index 94eebaf39194..bb63f438589f 100644 --- a/Container/composer.json +++ b/Container/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" } diff --git a/Container/tests/System/ClusterManagerClientTest.php b/Container/tests/System/ClusterManagerClientTest.php index ea806d774802..4d18f8ee6a22 100644 --- a/Container/tests/System/ClusterManagerClientTest.php +++ b/Container/tests/System/ClusterManagerClientTest.php @@ -20,7 +20,7 @@ use Google\Auth\CredentialsLoader; use Google\Cloud\Container\V1\ClusterManagerClient; use Google\Cloud\Container\V1\ListOperationsResponse; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group container @@ -36,7 +36,7 @@ class ClusterManagerClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -44,7 +44,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/ContainerAnalysis/composer.json b/ContainerAnalysis/composer.json index 80c2eaebce54..dc94a25996da 100644 --- a/ContainerAnalysis/composer.json +++ b/ContainerAnalysis/composer.json @@ -27,7 +27,8 @@ "google/grafeas": "^0.2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Core/composer.json b/Core/composer.json index 8fac5b0b52ce..c28f0a6e6582 100644 --- a/Core/composer.json +++ b/Core/composer.json @@ -14,7 +14,8 @@ "psr/http-message": "1.0.*" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Core/phpunit-snippets.xml.dist b/Core/phpunit-snippets.xml.dist index a0d737231f7e..a79a034513da 100644 --- a/Core/phpunit-snippets.xml.dist +++ b/Core/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Core/src/Testing/GcTestListener.php b/Core/src/Testing/GcTestListener.php index c351029be917..db16b91fbbc5 100644 --- a/Core/src/Testing/GcTestListener.php +++ b/Core/src/Testing/GcTestListener.php @@ -15,9 +15,17 @@ * limitations under the License. */ -class GcTestListener extends PHPUnit_Framework_BaseTestListener +use PHPUnit\Framework\TestListener; +use Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation; + +/** + * Garbage collector for tests + */ +class GcTestListener implements TestListener { - public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) + use TestListenerDefaultImplementation; + + public function end_test_suite($suite) { gc_collect_cycles(); } diff --git a/Core/src/Testing/Snippet/Coverage/ResultPrinter.php b/Core/src/Testing/Snippet/Coverage/ResultPrinter.php deleted file mode 100644 index 122f9e5e5d4b..000000000000 --- a/Core/src/Testing/Snippet/Coverage/ResultPrinter.php +++ /dev/null @@ -1,75 +0,0 @@ -uncovered(); - Container::reset(); - - if (!empty($uncovered)) { - $this->writeWithColor('bg-red', sprintf("NOTICE: %s uncovered snippets!", count($uncovered))); - - if ($this->verbose) { - $i = 0; - foreach ($uncovered as $snippet) { - $fqn = $snippet->fqn(); - $type = (strpos($fqn, '::') !== false) - ? 'Method' - : 'Class'; - - $this->write("$i: $type example: {$snippet->fqn()}[{$snippet->index()}]"); - $this->writeNewLine(); - $this->write("Declared on or around {$snippet->file()}:{$snippet->line()}"); - $this->writeNewLine(); - $this->writeNewLine(); - - $i++; - } - } else { - $this->write("Run command with `--verbose` flag to see uncovered snippets."); - } - - if (extension_loaded('grpc')) { - exit(1); - } - } - } -} diff --git a/Core/src/Testing/Snippet/SnippetTestCase.php b/Core/src/Testing/Snippet/SnippetTestCase.php index ab94c19ab842..a9801ae2de0c 100644 --- a/Core/src/Testing/Snippet/SnippetTestCase.php +++ b/Core/src/Testing/Snippet/SnippetTestCase.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\CheckForClassTrait; use Google\Cloud\Core\Testing\Snippet\Container; use Google\Cloud\Core\Testing\Snippet\Parser\Snippet; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Provide helpers for Snippet tests. @@ -43,7 +43,7 @@ class SnippetTestCase extends TestCase * @experimental * @internal */ - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$coverage = Container::$coverage; self::$parser = Container::$parser; diff --git a/Core/src/Testing/System/SystemTestCase.php b/Core/src/Testing/System/SystemTestCase.php index d269c0291859..280348ddcaf4 100644 --- a/Core/src/Testing/System/SystemTestCase.php +++ b/Core/src/Testing/System/SystemTestCase.php @@ -25,7 +25,7 @@ use Google\Cloud\Storage\Bucket; use Google\Cloud\Storage\StorageClient; use Google\Cloud\Core\Testing\System\DeletionQueue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * SystemTestCase can be extended to implement system tests diff --git a/Core/src/Testing/TestHelpers.php b/Core/src/Testing/TestHelpers.php index 5fb31f698128..c8e20d45fe7f 100644 --- a/Core/src/Testing/TestHelpers.php +++ b/Core/src/Testing/TestHelpers.php @@ -61,7 +61,7 @@ public static function stub($extends, array $args = [], array $props = []) } $reflection = new \ReflectionClass($name); - return $reflection->newInstanceArgs($args); + return $reflection->newInstanceArgs(array_values($args)); } /** diff --git a/Core/tests/Snippet/BlobTest.php b/Core/tests/Snippet/BlobTest.php index 119f4cc20436..8630684dd795 100644 --- a/Core/tests/Snippet/BlobTest.php +++ b/Core/tests/Snippet/BlobTest.php @@ -29,7 +29,7 @@ class BlobTest extends SnippetTestCase private $value; private $blob; - public function setUp() + public function set_up() { $this->value = 'foo'; $this->blob = new Blob($this->value); diff --git a/Core/tests/Snippet/Compute/MetadataTest.php b/Core/tests/Snippet/Compute/MetadataTest.php index 018e5c49165e..7229c3b4cb03 100644 --- a/Core/tests/Snippet/Compute/MetadataTest.php +++ b/Core/tests/Snippet/Compute/MetadataTest.php @@ -32,7 +32,7 @@ class MetadataTest extends SnippetTestCase private $metadata; private $reader; - public function setUp() + public function set_up() { $this->reader = $this->prophesize(ReaderInterface::class); $this->metadata = new Metadata; diff --git a/Core/tests/Snippet/DurationTest.php b/Core/tests/Snippet/DurationTest.php index c6903412446d..7be909ecbf38 100644 --- a/Core/tests/Snippet/DurationTest.php +++ b/Core/tests/Snippet/DurationTest.php @@ -30,7 +30,7 @@ class DurationTest extends SnippetTestCase private $duration; - public function setUp() + public function set_up() { $this->duration = new Duration(self::SECONDS, self::NANOS); } diff --git a/Core/tests/Snippet/GeoPointTest.php b/Core/tests/Snippet/GeoPointTest.php index 8d6ef53d6099..6e7d30d9dda6 100644 --- a/Core/tests/Snippet/GeoPointTest.php +++ b/Core/tests/Snippet/GeoPointTest.php @@ -28,7 +28,7 @@ class GeoPointTest extends SnippetTestCase private $point; private $gp; - public function setUp() + public function set_up() { $this->point = ['latitude' => 123.45, 'longitude' => 543.21]; $this->gp = new GeoPoint($this->point['latitude'], $this->point['longitude']); diff --git a/Core/tests/Snippet/Iam/IamTest.php b/Core/tests/Snippet/Iam/IamTest.php index ddc7a86a69e8..fa0a9a1596d1 100644 --- a/Core/tests/Snippet/Iam/IamTest.php +++ b/Core/tests/Snippet/Iam/IamTest.php @@ -34,7 +34,7 @@ class IamTest extends SnippetTestCase private $connection; - public function setUp() + public function set_up() { $this->policyData = []; $this->resource = 'testObject'; diff --git a/Core/tests/Snippet/Iam/PolicyBuilderTest.php b/Core/tests/Snippet/Iam/PolicyBuilderTest.php index 4af05a7e8083..940dd3770ed2 100644 --- a/Core/tests/Snippet/Iam/PolicyBuilderTest.php +++ b/Core/tests/Snippet/Iam/PolicyBuilderTest.php @@ -19,16 +19,19 @@ use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Google\Cloud\Core\Iam\PolicyBuilder; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group iam */ class PolicyBuilderTest extends SnippetTestCase { + use AssertIsType; + private $pb; private $policy; - public function setUp() + public function set_up() { $this->pb = new PolicyBuilder; $this->policy = ['etag' => 'foo']; @@ -39,7 +42,7 @@ public function testClass() $snippet = $this->snippetFromClass(PolicyBuilder::class); $res = $snippet->invoke('result'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } public function testSetBindings() @@ -97,6 +100,6 @@ public function testResult() $snippet->addLocal('builder', $this->pb); $res = $snippet->invoke('policy'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } } diff --git a/Core/tests/Snippet/Int64Test.php b/Core/tests/Snippet/Int64Test.php index 908021296fe2..126415990ba0 100644 --- a/Core/tests/Snippet/Int64Test.php +++ b/Core/tests/Snippet/Int64Test.php @@ -29,7 +29,7 @@ class Int64Test extends SnippetTestCase private $int64; - public function setUp() + public function set_up() { $this->int64 = new Int64((string)self::VALUE); } diff --git a/Core/tests/Snippet/LongRunning/LongRunningOperationTest.php b/Core/tests/Snippet/LongRunning/LongRunningOperationTest.php index bf67d690ca03..3c2c37cd0237 100644 --- a/Core/tests/Snippet/LongRunning/LongRunningOperationTest.php +++ b/Core/tests/Snippet/LongRunning/LongRunningOperationTest.php @@ -36,7 +36,7 @@ class LongRunningOperationTest extends SnippetTestCase const NAME = 'operations/foo'; const TYPE = 'test-type'; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(LongRunningConnectionInterface::class); $this->callables = [ diff --git a/Core/tests/Snippet/ServiceBuilderTest.php b/Core/tests/Snippet/ServiceBuilderTest.php index fbfdaf901785..52aade864993 100644 --- a/Core/tests/Snippet/ServiceBuilderTest.php +++ b/Core/tests/Snippet/ServiceBuilderTest.php @@ -39,7 +39,7 @@ class ServiceBuilderTest extends SnippetTestCase { private $cloud; - public function setUp() + public function set_up() { $this->cloud = new ServiceBuilder; } diff --git a/Core/tests/Snippet/Testing/Snippet/Parser/ParserTest.php b/Core/tests/Snippet/Testing/Snippet/Parser/ParserTest.php index fe193fc823f8..8490b078df01 100644 --- a/Core/tests/Snippet/Testing/Snippet/Parser/ParserTest.php +++ b/Core/tests/Snippet/Testing/Snippet/Parser/ParserTest.php @@ -35,7 +35,7 @@ class ParserTest extends SnippetTestCase private $methodExamples; private $allExamples; - public function setUp() + public function set_up() { $this->parser = new Parser(); $this->docBlock = new DocBlock(null); diff --git a/Core/tests/Snippet/Testing/System/SystemTestCaseTest.php b/Core/tests/Snippet/Testing/System/SystemTestCaseTest.php index 73d76ea1d6fc..c47a69d51312 100644 --- a/Core/tests/Snippet/Testing/System/SystemTestCaseTest.php +++ b/Core/tests/Snippet/Testing/System/SystemTestCaseTest.php @@ -24,6 +24,7 @@ use Foobar\Tests\System\Admin\Sub\AdminSubTestCase; use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Google\Cloud\Core\Testing\System\SystemTestCase; +use PHPUnit\Framework\SkippedTestError; /** * @group core @@ -90,14 +91,21 @@ public function testSkipIfEmulatorUsed() $customSnippet->invoke(); FoobarTestCase::setUsingEmulator(true); + + // For backwards compatibility with PHPUnit 4.8 and 5.0 + // This can be removed once support for PHP 5.5, 5.6, 7.0, and 7.1 is dropped + if (!class_exists('PHPUnit\Framework\SkippedTestError')) { + class_alias('PHPUnit_Framework_SkippedTestError', 'PHPUnit\Framework\SkippedTestError'); + } + try { $defaultSnippet->invoke(); - } catch (\RuntimeException $e) { + } catch (SkippedTestError $e) { $this->assertStringStartsWith('This test is not supported', $e->getMessage()); } try { $customSnippet->invoke(); - } catch (\RuntimeException $e) { + } catch (SkippedTestError $e) { $this->assertStringStartsWith('Administration functions are not supported', $e->getMessage()); } } @@ -108,10 +116,6 @@ public function testSkipIfEmulatorUsed() class FoobarTestCase extends \Google\Cloud\Core\Testing\System\SystemTestCase { - public static function markTestSkipped($message = '') - { - throw new \RuntimeException($message); - } } namespace Foobar\Sub; diff --git a/Core/tests/Snippet/TimestampTest.php b/Core/tests/Snippet/TimestampTest.php index 9c3b42569b9b..a79a092fb9d1 100644 --- a/Core/tests/Snippet/TimestampTest.php +++ b/Core/tests/Snippet/TimestampTest.php @@ -27,7 +27,7 @@ class TimestampTest extends SnippetTestCase { private $timestamp; - public function setUp() + public function set_up() { $this->dt = new \DateTime; $this->timestamp = new Timestamp($this->dt); diff --git a/Core/tests/System/Batch/BatchRunnerTest.php b/Core/tests/System/Batch/BatchRunnerTest.php index 50d30599060e..138aa8e44bed 100644 --- a/Core/tests/System/Batch/BatchRunnerTest.php +++ b/Core/tests/System/Batch/BatchRunnerTest.php @@ -19,7 +19,8 @@ use Google\Cloud\Core\Batch\BatchRunner; use Google\Cloud\Core\Batch\Retry; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group core @@ -31,6 +32,8 @@ */ class BatchRunnerTest extends TestCase { + use AssertStringContains; + private $runner; private static $daemon; @@ -49,7 +52,7 @@ public static function delTree($dir) return rmdir($dir); } - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$testDir = sprintf( '%s/google-cloud-system-test-%d', @@ -90,7 +93,7 @@ public static function setUpBeforeClass() } } - public static function tearDownAfterClass() + public static function tear_down_after_class() { @proc_terminate(self::$daemon); @proc_close(self::$daemon); @@ -101,7 +104,7 @@ public static function tearDownAfterClass() putenv('IS_BATCH_DAEMON_RUNNING'); } - public function setup() + public function set_up() { $this->runner = new BatchRunner(); $myJob = new MyJob(self::$commandFile, self::$targetFile); @@ -124,7 +127,7 @@ public function getResult() public function assertResultContains($expected) { - $this->assertContains($expected, $this->getResult()); + $this->assertStringContainsString($expected, $this->getResult()); } public function testSubmit() diff --git a/Core/tests/Unit/AnonymousCredentialsTest.php b/Core/tests/Unit/AnonymousCredentialsTest.php index d837e7c4b4f0..cf68b3cde3de 100644 --- a/Core/tests/Unit/AnonymousCredentialsTest.php +++ b/Core/tests/Unit/AnonymousCredentialsTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Core\Tests\Unit; use Google\Cloud\Core\AnonymousCredentials; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -30,7 +30,7 @@ class AnonymousCredentialsTest extends TestCase 'access_token' => null ]; - public function setUp() + public function set_up() { $this->credentials = new AnonymousCredentials(); } diff --git a/Core/tests/Unit/ArrayTraitTest.php b/Core/tests/Unit/ArrayTraitTest.php index 45ea7bf704cc..ca5505f07bac 100644 --- a/Core/tests/Unit/ArrayTraitTest.php +++ b/Core/tests/Unit/ArrayTraitTest.php @@ -19,16 +19,19 @@ use Google\Cloud\Core\ArrayTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class ArrayTraitTest extends TestCase { + use ExpectException; + private $impl; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(ArrayTrait::class); } @@ -44,11 +47,10 @@ public function testPluck() $this->assertEquals([], $array); } - /** - * @expectedException \InvalidArgumentException - */ public function testPluckThrowsExceptionWithInvalidKey() { + $this->expectException('\InvalidArgumentException'); + $array = []; $this->impl->call('pluck', ['not_here', &$array]); } diff --git a/Core/tests/Unit/Batch/BatchDaemonTraitTest.php b/Core/tests/Unit/Batch/BatchDaemonTraitTest.php index 46b68914fccc..a3ecb46ad854 100644 --- a/Core/tests/Unit/Batch/BatchDaemonTraitTest.php +++ b/Core/tests/Unit/Batch/BatchDaemonTraitTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Batch\BatchDaemonTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -27,7 +27,7 @@ */ class BatchDaemonTraitTest extends TestCase { - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(BatchDaemonTrait::class); } diff --git a/Core/tests/Unit/Batch/BatchRunnerTest.php b/Core/tests/Unit/Batch/BatchRunnerTest.php index e00ac9b8a305..85a2fc2bf832 100644 --- a/Core/tests/Unit/Batch/BatchRunnerTest.php +++ b/Core/tests/Unit/Batch/BatchRunnerTest.php @@ -23,7 +23,8 @@ use Google\Cloud\Core\Batch\ConfigStorageInterface; use Google\Cloud\Core\Batch\ProcessItemInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -31,21 +32,22 @@ */ class BatchRunnerTest extends TestCase { + use ExpectException; + private $configStorage; private $processor; - public function setUp() + public function set_up() { $this->configStorage = $this->prophesize(ConfigStorageInterface::class); $this->processor = $this->prophesize(ProcessItemInterface::class); $this->batchConfig = $this->prophesize(JobConfig::class); } - /** - * @expectedException \InvalidArgumentException - */ public function testRegisterJobClosure() { + $this->expectException('\InvalidArgumentException'); + $runner = new BatchRunner( $this->configStorage->reveal(), $this->processor->reveal() diff --git a/Core/tests/Unit/Batch/BatchTraitTest.php b/Core/tests/Unit/Batch/BatchTraitTest.php index 677915f9bc7c..885d50de1ed2 100644 --- a/Core/tests/Unit/Batch/BatchTraitTest.php +++ b/Core/tests/Unit/Batch/BatchTraitTest.php @@ -24,6 +24,8 @@ use Google\Cloud\Core\Tests\Unit\Batch\Fixtures\BatchClass; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group core @@ -31,6 +33,9 @@ */ class BatchTraitTest extends TestCase { + use AssertStringContains; + use ExpectException; + const ID = 'some-id'; const BATCH_METHOD = 'doBatch'; @@ -79,23 +84,21 @@ public function testSend() $this->assertTrue($hasExecuted); $this->assertEquals(count($items), $count); - $this->assertContains('seconds for ' . self::BATCH_METHOD, $contents); + $this->assertStringContainsString('seconds for ' . self::BATCH_METHOD, $contents); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetCommonBatchPropertiesThrowsExceptionWithoutIdentifier() { + $this->expectException('\InvalidArgumentException'); + $impl = new BatchClass(); $impl->setCommonBatchProperties(['batchMethod' => self::BATCH_METHOD]); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetCommonBatchPropertiesThrowsExceptionWithoutBatchMethod() { + $this->expectException('\InvalidArgumentException'); + $impl = new BatchClass(); $impl->setCommonBatchProperties(['identifier' => self::ID]); } diff --git a/Core/tests/Unit/Batch/HandleFailureTraitTest.php b/Core/tests/Unit/Batch/HandleFailureTraitTest.php index 8e4bed05830f..1b961e92e9ce 100644 --- a/Core/tests/Unit/Batch/HandleFailureTraitTest.php +++ b/Core/tests/Unit/Batch/HandleFailureTraitTest.php @@ -19,7 +19,8 @@ use Google\Cloud\Core\Batch\HandleFailureTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -27,6 +28,7 @@ */ class HandleFailureTraitTest extends TestCase { + use ExpectException; private $impl; private $testDir; @@ -41,7 +43,7 @@ public function delTree($dir) return rmdir($dir); } - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(HandleFailureTrait::class); $this->testDir = sprintf( @@ -53,18 +55,20 @@ public function setUp() putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR'); } - public function tearDown() + public function tear_down() { $this->delTree($this->testDir); putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR'); } - /** - * @ExpectedException \RuntimeException - */ public function testInitFailureFileThrowsException() { - putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR=/tmp/non-existent/subdir'); + if (0 === posix_getuid()) { + $this->markTestSkipped('Cannot test init failure as root'); + } + $this->expectException('\RuntimeException'); + + putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR=/bad/write/dir'); $this->impl->call('initFailureFile'); } diff --git a/Core/tests/Unit/Batch/InMemoryConfigStorageTest.php b/Core/tests/Unit/Batch/InMemoryConfigStorageTest.php index e6e1b08ae536..ab14414f6195 100644 --- a/Core/tests/Unit/Batch/InMemoryConfigStorageTest.php +++ b/Core/tests/Unit/Batch/InMemoryConfigStorageTest.php @@ -21,6 +21,7 @@ use Google\Cloud\Core\Batch\InMemoryConfigStorage; use Google\Cloud\Core\Batch\JobConfig; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -28,6 +29,8 @@ */ class InMemoryConfigStorageTest extends TestCase { + use ExpectException; + private $items; public function testSingletonEquality() @@ -100,22 +103,20 @@ function ($id) { ); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Serialization not supported - */ public function testSerializeThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Serialization not supported'); + $configStorage = InMemoryConfigStorage::getInstance(); serialize($configStorage); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Serialization not supported - */ public function testUnserializeThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Serialization not supported'); + $configStorage = InMemoryConfigStorage::getInstance(); $configStorage->__wakeup(); } diff --git a/Core/tests/Unit/Batch/JobConfigTest.php b/Core/tests/Unit/Batch/JobConfigTest.php index c860f05f0ad5..75d7da22ba29 100644 --- a/Core/tests/Unit/Batch/JobConfigTest.php +++ b/Core/tests/Unit/Batch/JobConfigTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Batch\JobConfig; use Google\Cloud\Core\Batch\BatchJob; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -32,7 +32,7 @@ class JobConfigTest extends TestCase private $func; private $idNum; - public function setUp() + public function set_up() { $this->config = new JobConfig(); $this->identifier = 'job1'; diff --git a/Core/tests/Unit/Batch/OpisClosureSerializerTest.php b/Core/tests/Unit/Batch/OpisClosureSerializerTest.php index 980011e448ac..bb61917d719b 100644 --- a/Core/tests/Unit/Batch/OpisClosureSerializerTest.php +++ b/Core/tests/Unit/Batch/OpisClosureSerializerTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Batch\OpisClosureSerializer; use Opis\Closure\SerializableClosure; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -29,7 +29,7 @@ class OpisClosureSerializerTest extends TestCase { private $serialzer; - public function setUp() + public function set_up() { $this->serializer = new OpisClosureSerializer(); } diff --git a/Core/tests/Unit/Batch/RetryTest.php b/Core/tests/Unit/Batch/RetryTest.php index 700fc73591ef..816e021e16df 100644 --- a/Core/tests/Unit/Batch/RetryTest.php +++ b/Core/tests/Unit/Batch/RetryTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Batch\BatchJob; use Google\Cloud\Core\Batch\BatchRunner; use Google\Cloud\Core\Batch\Retry; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -43,7 +43,7 @@ public static function delTree($dir) return rmdir($dir); } - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$testDir = sprintf( '%s/google-cloud-unit-test-%d', @@ -53,13 +53,13 @@ public static function setUpBeforeClass() putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR=' . self::$testDir); } - public static function tearDownAfterClass() + public static function tear_down_after_class() { self::delTree(self::$testDir); putenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR'); } - public function setUp() + public function set_up() { $this->runner = $this->prophesize(BatchRunner::class); $this->job = $this->prophesize(BatchJob::class); diff --git a/Core/tests/Unit/Batch/SimpleJobTraitTest.php b/Core/tests/Unit/Batch/SimpleJobTraitTest.php index 37ce47301043..f9abcb227a3f 100644 --- a/Core/tests/Unit/Batch/SimpleJobTraitTest.php +++ b/Core/tests/Unit/Batch/SimpleJobTraitTest.php @@ -22,6 +22,7 @@ use Google\Cloud\Core\Batch\SimpleJob; use Google\Cloud\Core\Batch\SimpleJobTrait; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -29,13 +30,14 @@ */ class SimpleJobTraitTest extends TestCase { + use ExpectException; + const ID = 'simple-job'; - /** - * @expectedException \InvalidArgumentException - */ public function testSetSimpleJobPropertiesThrowsExceptionWithoutIdentifier() { + $this->expectException('\InvalidArgumentException'); + $job = new SimpleClass(); $job->setSimpleJobProperties([]); } diff --git a/Core/tests/Unit/Batch/SysvConfigStorageTest.php b/Core/tests/Unit/Batch/SysvConfigStorageTest.php index 3cfb4822541b..fc19f819ef03 100644 --- a/Core/tests/Unit/Batch/SysvConfigStorageTest.php +++ b/Core/tests/Unit/Batch/SysvConfigStorageTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Core\Batch\SysvConfigStorage; use Google\Cloud\Core\SysvTrait; use Google\Cloud\Core\Tests\Unit\Batch\Fixtures\TestSerializableObjectWithClosure; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -40,7 +40,7 @@ class SysvConfigStorageTest extends TestCase private $originalProject; - public function setUp() + public function set_up() { if (! $this->isSysvIPCLOaded()) { $this->markTestSkipped( @@ -53,7 +53,7 @@ public function setUp() $this->originalProject = getenv('GOOGLE_CLOUD_BATCH_PROJECT'); } - public function tearDown() + public function tear_down() { if ($this->originalShmSize === false) { putenv("GOOGLE_CLOUD_BATCH_SHM_SIZE"); diff --git a/Core/tests/Unit/Batch/SysvProcessorTest.php b/Core/tests/Unit/Batch/SysvProcessorTest.php index 8d0a75fdc771..867ad5300448 100644 --- a/Core/tests/Unit/Batch/SysvProcessorTest.php +++ b/Core/tests/Unit/Batch/SysvProcessorTest.php @@ -20,7 +20,8 @@ use Google\Cloud\Core\Batch\BatchDaemonTrait; use Google\Cloud\Core\Batch\SysvProcessor; use Google\Cloud\Core\SysvTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -28,6 +29,7 @@ */ class SysvProcessorTest extends TestCase { + use ExpectException; use BatchDaemonTrait; use SysvTrait; @@ -35,7 +37,7 @@ class SysvProcessorTest extends TestCase private $processor; private $queue; - public function setUp() + public function set_up() { putenv('GOOGLE_CLOUD_SYSV_ID=U'); if (! $this->isSysvIPCLoaded()) { @@ -48,7 +50,7 @@ public function setUp() $this->clearQueue(); } - public function tearDown() + public function tear_down() { if ($this->isSysvIPCLoaded()) { $this->clearQueue(); @@ -135,10 +137,11 @@ public function testQueueOverflowDirect() * Test that submit() method does not stall. * * @depends testQueueOverflowDirect - * @expectedException \Google\Cloud\Core\Batch\QueueOverflowException */ public function testQueueOverflowFile() { + $this->expectException('\Google\Cloud\Core\Batch\QueueOverflowException'); + $queueSize = $this->queueSize(); $item = str_repeat('a', 8160); while ($queueSize >= 8192) { diff --git a/Core/tests/Unit/CallTraitTest.php b/Core/tests/Unit/CallTraitTest.php index 4d5ab958949c..3dc64b0afe3f 100644 --- a/Core/tests/Unit/CallTraitTest.php +++ b/Core/tests/Unit/CallTraitTest.php @@ -19,12 +19,17 @@ use Google\Cloud\Core\CallTrait; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; /** * @group core */ class CallTraitTest extends TestCase { + use ExpectException; + use ExpectPHPException; + public function testCall() { $t = new CallTraitStub(['foo' => 'bar']); @@ -32,11 +37,10 @@ public function testCall() $this->assertEquals('bar', $t->foo()); } - /** - * @expectedException PHPUnit_Framework_Error - */ public function testErr() { + $this->expectError(); + $t = new CallTraitStub(['foo' => 'bar']); $t->bar(); diff --git a/Core/tests/Unit/ClientTraitTest.php b/Core/tests/Unit/ClientTraitTest.php index 8e8008c0f450..b6995d9aac44 100644 --- a/Core/tests/Unit/ClientTraitTest.php +++ b/Core/tests/Unit/ClientTraitTest.php @@ -21,7 +21,9 @@ use Google\Cloud\Core\Compute\Metadata; use Google\Cloud\Core\Testing\TestHelpers; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; /** * @group core @@ -29,10 +31,13 @@ */ class ClientTraitTest extends TestCase { + use ExpectException; + use ExpectPHPException; + private $impl; private $dependency; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(ClientTrait::class); @@ -42,11 +47,12 @@ public function setUp() } /** - * @expectedException Google\Cloud\Core\Exception\GoogleException * @dataProvider invalidDependencyStatusProvider */ public function testGetConnectionTypeInvalidStatus($dependencyStatus, $config) { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $this->dependency->___setProperty('dependencyStatus', $dependencyStatus); $this->dependency->call('getConnectionType', [$config]); } @@ -113,11 +119,10 @@ public function testRequireGrpcPassesWithGrpc() ); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testRequireGrpcThrowsExceptionWithoutGrpc() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $this->dependency->___setProperty('dependencyStatus', false); $this->dependency->call('requireGrpc'); } @@ -160,11 +165,10 @@ public function testConfigureAuthenticationWithKeyFilePath() $this->assertEquals('example_project', $this->impl->___getProperty('projectId')); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testConfigureAuthenticationWithInvalidKeyFilePath() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $keyFilePath = __DIR__ . '/i/sure/hope/this/doesnt/exist'; $conf = $this->impl->call('configureAuthentication', [[ @@ -172,11 +176,10 @@ public function testConfigureAuthenticationWithInvalidKeyFilePath() ]]); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testConfigureAuthenticationWithKeyFileThatCantBeDecoded() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $keyFilePath = __DIR__ . '/ClientTraitTest.php'; $conf = $this->impl->call('configureAuthentication', [[ @@ -184,11 +187,10 @@ public function testConfigureAuthenticationWithKeyFileThatCantBeDecoded() ]]); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testDetectProjectIdWithNoProjectIdAvailable() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $conf = $this->impl->call('detectProjectId', [[ 'projectIdRequired' => true, 'httpHandler' => function ($request, $options = []) { @@ -285,11 +287,10 @@ public function testDetectNumericProjectIdOnGce() $this->assertEquals($res, $projectId); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testDetectProjectIdOnGceButOhNoThereStillIsntAProjectId() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $projectId = null; $m = $this->prophesize(Metadata::class); @@ -327,12 +328,11 @@ public function testDetectProjectIdEmulator() $this->assertEquals($projectId, $res); } - /** - * @expectedException PHPUnit_Framework_Error_Notice - * @expectedExceptionMessageRegExp /A keyfile was given/ - */ public function testDetectProjectIdWithKeyfileMissingProjectId() { + $this->expectNotice(); + $this->expectNoticeMessage('A keyfile was given'); + $trait = TestHelpers::impl(ClientTrait::class); $res = $trait->call('detectProjectId', [[ diff --git a/Core/tests/Unit/Compute/Metadata/Readers/HttpHandlerReaderTest.php b/Core/tests/Unit/Compute/Metadata/Readers/HttpHandlerReaderTest.php index eb78a16b8d7b..aaaacea231bb 100644 --- a/Core/tests/Unit/Compute/Metadata/Readers/HttpHandlerReaderTest.php +++ b/Core/tests/Unit/Compute/Metadata/Readers/HttpHandlerReaderTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Core\Compute\Metadata\Readers\HttpHandlerReader; use Google\Cloud\Core\Testing\TestHelpers; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Psr\Http\Message\RequestInterface; /** @@ -33,7 +33,7 @@ class HttpHandlerReaderTest extends TestCase private $reader; private $handler; - public function setUp() + public function set_up() { $this->reader = TestHelpers::stub(HttpHandlerReader::class, [], [ 'httpHandler' diff --git a/Core/tests/Unit/Compute/MetadataTest.php b/Core/tests/Unit/Compute/MetadataTest.php index ca32ada59439..d196b613213a 100644 --- a/Core/tests/Unit/Compute/MetadataTest.php +++ b/Core/tests/Unit/Compute/MetadataTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Core\Compute\Metadata\Readers\ReaderInterface; use Google\Cloud\Core\Compute\Metadata\Readers\StreamReader; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -32,7 +32,7 @@ class MetadataTest extends TestCase private $metadata; private $reader; - public function setUp() + public function set_up() { $this->metadata = TestHelpers::stub(Metadata::class, [], ['reader']); $this->reader = $this->prophesize(ReaderInterface::class); diff --git a/Core/tests/Unit/ConcurrencyControlTraitTest.php b/Core/tests/Unit/ConcurrencyControlTraitTest.php index dfa699c690ad..9b9d9511c32a 100644 --- a/Core/tests/Unit/ConcurrencyControlTraitTest.php +++ b/Core/tests/Unit/ConcurrencyControlTraitTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\ConcurrencyControlTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -30,7 +30,7 @@ class ConcurrencyControlTraitTest extends TestCase private $trait; - public function setUp() + public function set_up() { $this->trait = TestHelpers::impl(ConcurrencyControlTrait::class); } diff --git a/Core/tests/Unit/DurationTest.php b/Core/tests/Unit/DurationTest.php index f22cf5aad671..67a43bd085be 100644 --- a/Core/tests/Unit/DurationTest.php +++ b/Core/tests/Unit/DurationTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Core\Tests\Unit; use Google\Cloud\Core\Duration; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -30,7 +30,7 @@ class DurationTest extends TestCase private $duration; - public function setUp() + public function set_up() { $this->duration = new Duration(self::SECONDS, self::NANOS); } diff --git a/Core/tests/Unit/EmulatorTraitTest.php b/Core/tests/Unit/EmulatorTraitTest.php index c8bd438281b2..dbbef08c87cf 100644 --- a/Core/tests/Unit/EmulatorTraitTest.php +++ b/Core/tests/Unit/EmulatorTraitTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\EmulatorTrait; use Google\Cloud\Core\Testing\GrpcTestTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -31,7 +31,7 @@ class EmulatorTraitTest extends TestCase private $impl; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(EmulatorTrait::class); } diff --git a/Core/tests/Unit/ExponentialBackoffTest.php b/Core/tests/Unit/ExponentialBackoffTest.php index eff5a4f7bdcb..bc147db542f4 100644 --- a/Core/tests/Unit/ExponentialBackoffTest.php +++ b/Core/tests/Unit/ExponentialBackoffTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\ExponentialBackoff; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -28,7 +28,7 @@ class ExponentialBackoffTest extends TestCase { private $delayFunction; - public function setUp() + public function set_up() { $this->delayFunction = function () { return; diff --git a/Core/tests/Unit/GeoPointTest.php b/Core/tests/Unit/GeoPointTest.php index 484cd5a53081..400fa82bd820 100644 --- a/Core/tests/Unit/GeoPointTest.php +++ b/Core/tests/Unit/GeoPointTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Core\GeoPoint; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -26,6 +27,8 @@ */ class GeoPointTest extends TestCase { + use ExpectException; + public function testGeoPoint() { $point = new GeoPoint(1.1, 2.2); @@ -54,20 +57,22 @@ public function testPoint() /** * @dataProvider methods - * @expectedException InvalidArgumentException */ public function testCheckContext($method) { + $this->expectException('InvalidArgumentException'); + $point = new GeoPoint(1.1, 2.2); $point->$method(222.33); } /** * @dataProvider methods - * @expectedException InvalidArgumentException */ public function testInvalidType($method) { + $this->expectException('InvalidArgumentException'); + $method = 'set' . ucfirst($method); $point = new GeoPoint(1.1, 2.2); $point->$method('foo'); @@ -75,10 +80,11 @@ public function testInvalidType($method) /** * @dataProvider methods - * @expectedException InvalidArgumentException */ public function testSetNullValue($method) { + $this->expectException('InvalidArgumentException'); + $method = 'set' . ucfirst($method); $point = new GeoPoint(1.1, 2.2, true); $point->$method(null); diff --git a/Core/tests/Unit/GrpcRequestWrapperTest.php b/Core/tests/Unit/GrpcRequestWrapperTest.php index 4fadd68ac863..525e87010d82 100644 --- a/Core/tests/Unit/GrpcRequestWrapperTest.php +++ b/Core/tests/Unit/GrpcRequestWrapperTest.php @@ -35,16 +35,18 @@ use Google\Rpc\Code; use Google\Rpc\PreconditionFailure; use Google\Rpc\Status; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class GrpcRequestWrapperTest extends TestCase { + use ExpectException; use GrpcTestTrait; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } @@ -107,11 +109,10 @@ public function responseProvider() ]; } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenRequestFails() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $requestWrapper = new GrpcRequestWrapper(); $requestWrapper->send(function () { @@ -163,11 +164,10 @@ public function testReturnsStreamedResponse() } } - /** - * @expectedException InvalidArgumentException - */ public function testThrowsExceptionWithInvalidCredentialsFetcher() { + $this->expectException('InvalidArgumentException'); + $credentialsFetcher = new \stdClass(); $requestWrapper = new GrpcRequestWrapper([ diff --git a/Core/tests/Unit/GrpcTraitTest.php b/Core/tests/Unit/GrpcTraitTest.php index 7314be97fdbf..00b63933d301 100644 --- a/Core/tests/Unit/GrpcTraitTest.php +++ b/Core/tests/Unit/GrpcTraitTest.php @@ -25,7 +25,8 @@ use Google\Cloud\Core\GrpcTrait; use Google\Cloud\Core\Testing\GrpcTestTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; use Prophecy\Argument; /** @@ -33,12 +34,13 @@ */ class GrpcTraitTest extends TestCase { + use AssertStringContains; use GrpcTestTrait; private $implementation; private $requestWrapper; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -114,7 +116,7 @@ public function testSendsRequestNotFoundWhitelisted() $msg = $e->getMessage(); } - $this->assertContains('NOTE: Error may be due to Whitelist Restriction.', $msg); + $this->assertStringContainsString('NOTE: Error may be due to Whitelist Restriction.', $msg); } public function testSendsRequestNotFoundNotWhitelisted() @@ -137,7 +139,7 @@ public function testSendsRequestNotFoundNotWhitelisted() $msg = $e->getMessage(); } - $this->assertNotContains('NOTE: Error may be due to Whitelist Restriction.', $msg); + $this->assertStringNotContainsString('NOTE: Error may be due to Whitelist Restriction.', $msg); } public function testGetsGaxConfig() diff --git a/Core/tests/Unit/Iam/IamTest.php b/Core/tests/Unit/Iam/IamTest.php index 5786203bc445..c2bb07e9459b 100644 --- a/Core/tests/Unit/Iam/IamTest.php +++ b/Core/tests/Unit/Iam/IamTest.php @@ -21,7 +21,8 @@ use Google\Cloud\Core\Iam\IamConnectionInterface; use Google\Cloud\Core\Iam\PolicyBuilder; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -29,11 +30,13 @@ */ class IamTest extends TestCase { + use ExpectException; + const RESOURCE = 'projects/my-project/topics/my-topic'; private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(IamConnectionInterface::class); } @@ -101,11 +104,10 @@ public function testSetPolicyWithPolicyBuilder() $this->assertEquals($policies[1], $res); } - /** - * @expectedException InvalidArgumentException - */ public function testSetPolicyWithInvalidPolicy() { + $this->expectException('InvalidArgumentException'); + $iam = new Iam($this->connection->reveal(), self::RESOURCE); $res = $iam->setPolicy('foo'); } diff --git a/Core/tests/Unit/Iam/PolicyBuilderTest.php b/Core/tests/Unit/Iam/PolicyBuilderTest.php index d66f2adfa261..ed5dfaa04d7d 100644 --- a/Core/tests/Unit/Iam/PolicyBuilderTest.php +++ b/Core/tests/Unit/Iam/PolicyBuilderTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Core\Iam\PolicyBuilder; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -26,6 +27,8 @@ */ class PolicyBuilderTest extends TestCase { + use ExpectException; + public function testBuilder() { $role = 'test'; @@ -61,11 +64,10 @@ public function testBuilder() $this->assertEquals($policy, $result); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidPolicy() { + $this->expectException('InvalidArgumentException'); + $policy = ['foo' => 'bar']; $builder = new PolicyBuilder($policy); } @@ -139,24 +141,22 @@ public function testConstructWithExistingPolicy() $this->assertEquals($policy, $result); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Helper methods cannot be invoked on policies with version 3. - */ public function testAddBindingVersionThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Helper methods cannot be invoked on policies with version 3.'); + $builder = new PolicyBuilder(); $builder->setVersion(3); $builder->addBinding('test', ['user:test@test.com']); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Helper methods cannot be invoked on policies containing conditions. - */ public function testAddBindingWithConditionsThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Helper methods cannot be invoked on policies containing conditions.'); + $policy = [ 'bindings' => [ [ @@ -221,12 +221,11 @@ public function testRemoveBindingAndRole() $this->assertEquals('user2:test@test.com', $builder->result()['bindings'][0]['members'][0]); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage One or more role-members were not found. - */ public function testRemoveBindingInvalidMemberThrowsException() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('One or more role-members were not found.'); + $policy = [ 'bindings' => [ [ @@ -242,12 +241,11 @@ public function testRemoveBindingInvalidMemberThrowsException() $builder->removeBinding('test', ['user2:test@test.com']); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The role was not found. - */ public function testRemoveBindingInvalidRoleThrowsException() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The role was not found.'); + $policy = [ 'bindings' => [ [ @@ -263,12 +261,11 @@ public function testRemoveBindingInvalidRoleThrowsException() $builder->removeBinding('test2', ['user:test@test.com']); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Helper methods cannot be invoked on policies with version 3. - */ public function testRemoveBindingVersionThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Helper methods cannot be invoked on policies with version 3.'); + $policy = [ 'version' => 3, 'bindings' => [ @@ -285,12 +282,11 @@ public function testRemoveBindingVersionThrowsException() $builder->removeBinding('test', ['user:test@test.com']); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Helper methods cannot be invoked on policies containing conditions. - */ public function testRemoveBindingWithConditionsThrowsException() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Helper methods cannot be invoked on policies containing conditions.'); + $policy = [ 'bindings' => [ [ diff --git a/Core/tests/Unit/JsonTraitTest.php b/Core/tests/Unit/JsonTraitTest.php index 04237262d76a..95adbe7de8fe 100644 --- a/Core/tests/Unit/JsonTraitTest.php +++ b/Core/tests/Unit/JsonTraitTest.php @@ -19,16 +19,19 @@ use Google\Cloud\Core\JsonTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class JsonTraitTest extends TestCase { + use ExpectException; + private $implementation; - public function setUp() + public function set_up() { $this->implementation = TestHelpers::impl(JsonTrait::class); } @@ -38,11 +41,10 @@ public function testJsonEncode() $this->assertEquals('10', $this->implementation->call('jsonEncode', [10])); } - /** - * @expectedException \InvalidArgumentException - */ public function testJsonEncodeThrowsException() { + $this->expectException('\InvalidArgumentException'); + $this->implementation->call('jsonEncode', [fopen('php://temp', 'r')]); } @@ -51,11 +53,10 @@ public function testJsonDecode() $this->assertEquals(10, $this->implementation->call('jsonDecode', ['10'])); } - /** - * @expectedException \InvalidArgumentException - */ public function testJsonDecodeThrowsException() { + $this->expectException('\InvalidArgumentException'); + $this->implementation->call('jsonDecode', ['.|.']); } } diff --git a/Core/tests/Unit/Lock/CommonLockTrait.php b/Core/tests/Unit/Lock/CommonLockTrait.php index dfdf66ca2306..3442f877d505 100644 --- a/Core/tests/Unit/Lock/CommonLockTrait.php +++ b/Core/tests/Unit/Lock/CommonLockTrait.php @@ -20,6 +20,7 @@ use Google\Cloud\Core\Testing\Lock\MockValues; use Google\Cloud\Core\Lock\SemaphoreLock; use Google\Cloud\Core\SysvTrait; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -27,6 +28,8 @@ */ trait CommonLockTrait { + use ExpectException; + private $lock; private function setLock($lock) @@ -57,11 +60,10 @@ public function testSynchronizeLock() $this->assertTrue($return); } - /** - * @expectedException \Exception - */ public function testSynchronizeLockThrowsException() { + $this->expectException('\Exception'); + $this->lock->synchronize(function () { throw new \Exception(); }); diff --git a/Core/tests/Unit/Lock/FlockLockTest.php b/Core/tests/Unit/Lock/FlockLockTest.php index 3261ddd28535..da49e2f5ad93 100644 --- a/Core/tests/Unit/Lock/FlockLockTest.php +++ b/Core/tests/Unit/Lock/FlockLockTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Lock\FlockLock; use Google\Cloud\Core\Testing\Lock\MockValues; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -31,47 +31,43 @@ class FlockLockTest extends TestCase const LOCK_NAME = 'test'; - public function setUp() + public function set_up() { MockValues::initialize(); $this->setLock(new FlockLock(self::LOCK_NAME)); } - /** - * @expectedException \InvalidArgumentException - */ public function testThrowsExceptionWithInvalidFileName() { + $this->expectException('\InvalidArgumentException'); + new FlockLock(123); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to acquire lock. - */ public function testThrowsExceptionWhenFlockFailsOnAcquire() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to acquire lock.'); + MockValues::$flockReturnValue = false; $this->lock->acquire(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to release lock. - */ public function testThrowsExceptionWhenFlockFailsOnRelease() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to release lock.'); + $this->lock->acquire(); MockValues::$flockReturnValue = false; $this->lock->release(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to open lock file. - */ public function testThrowsExceptionWhenFopenFails() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to open lock file.'); + MockValues::$fopenReturnValue = false; $this->lock->acquire(); } diff --git a/Core/tests/Unit/Lock/SemaphoreLockTest.php b/Core/tests/Unit/Lock/SemaphoreLockTest.php index 8f34ceda6cd5..9ded6d593fc7 100644 --- a/Core/tests/Unit/Lock/SemaphoreLockTest.php +++ b/Core/tests/Unit/Lock/SemaphoreLockTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Lock\SemaphoreLock; use Google\Cloud\Core\SysvTrait; use Google\Cloud\Core\Testing\Lock\MockValues; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -33,7 +33,7 @@ class SemaphoreLockTest extends TestCase const LOCK_NAME = 'test'; - public function setUp() + public function set_up() { if (!$this->isSysvIPCLoaded()) { $this->markTestSkipped( @@ -45,41 +45,37 @@ public function setUp() MockValues::initialize(); } - /** - * @expectedException \InvalidArgumentException - */ public function testThrowsExceptionWithInvalidKey() { + $this->expectException('\InvalidArgumentException'); + new SemaphoreLock('abc'); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to acquire lock. - */ public function testThrowsExceptionWhenSemAcquireFailsOnAcquire() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to acquire lock.'); + MockValues::$sem_acquireReturnValue = false; $this->lock->acquire(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to release lock. - */ public function testThrowsExceptionWhenSemReleaseFailsOnRelease() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to release lock.'); + $this->lock->acquire(); MockValues::$sem_releaseReturnValue = false; $this->lock->release(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Failed to generate semaphore ID. - */ public function testThrowsExceptionWhenSemGetFails() { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('Failed to generate semaphore ID.'); + MockValues::$sem_getReturnValue = false; $this->lock->acquire(); } diff --git a/Core/tests/Unit/Logger/AppEngineFlexHandlerTest.php b/Core/tests/Unit/Logger/AppEngineFlexHandlerTest.php index 0f53b3a311d6..813cbf6251e1 100644 --- a/Core/tests/Unit/Logger/AppEngineFlexHandlerTest.php +++ b/Core/tests/Unit/Logger/AppEngineFlexHandlerTest.php @@ -19,7 +19,9 @@ use Google\Cloud\Core\Logger\AppEngineFlexHandlerFactory; use Monolog\Logger; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group core @@ -27,10 +29,13 @@ */ class AppEngineFlexHandlerTest extends TestCase { + use AssertStringContains; + use AssertIsType; + private $stream; private $log; - public function setUp() + public function set_up() { $this->stream = tmpfile(); @@ -40,7 +45,7 @@ public function setUp() $this->log->pushHandler($handler); } - public function tearDown() + public function tear_down() { fclose($this->stream); } @@ -52,9 +57,9 @@ public function testOneLine() rewind($this->stream); $log_text = stream_get_contents($this->stream); $log_array = json_decode($log_text, true); - $this->assertContains($msg, $log_array['message']); - $this->assertInternalType('int', $log_array['timestamp']['seconds']); - $this->assertInternalType('int', $log_array['timestamp']['nanos']); + $this->assertStringContainsString($msg, $log_array['message']); + $this->assertIsInt($log_array['timestamp']['seconds']); + $this->assertIsInt($log_array['timestamp']['nanos']); $this->assertEquals('ERROR', $log_array['severity']); } @@ -67,9 +72,9 @@ public function testOneLineWithTraceContext() rewind($this->stream); $log_text = stream_get_contents($this->stream); $log_array = json_decode($log_text, true); - $this->assertContains($msg, $log_array['message']); - $this->assertInternalType('int', $log_array['timestamp']['seconds']); - $this->assertInternalType('int', $log_array['timestamp']['nanos']); + $this->assertStringContainsString($msg, $log_array['message']); + $this->assertIsInt($log_array['timestamp']['seconds']); + $this->assertIsInt($log_array['timestamp']['nanos']); $this->assertEquals('ERROR', $log_array['severity']); $this->assertEquals('foo', $log_array['traceId']); diff --git a/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php b/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php index f8af5a3a6da2..bb72d828f467 100644 --- a/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php +++ b/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php @@ -18,7 +18,6 @@ namespace Google\Cloud\Core\Tests\Unit\LongRunning; use Google\ApiCore\OperationResponse; -use PHPUnit\Framework\TestCase; use Google\Cloud\Core\LongRunning\OperationResponseTrait; use Google\Cloud\Core\LongRunning\LongRunningOperation; use Google\Cloud\Core\LongRunning\LongRunningConnectionInterface; @@ -26,6 +25,7 @@ use Prophecy\Argument; use Google\Cloud\Audit\RequestMetadata; use Google\Cloud\Audit\AuthorizationInfo; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -51,7 +51,7 @@ class OperationResponseTraitTest extends TestCase ], ]; - public function setUp() + public function set_up() { $serializer = $this->prophesize(Serializer::class); $serializer->encodeMessage(Argument::any())->will(function ($arg) { diff --git a/Core/tests/Unit/Report/EmptyMetadataProviderTest.php b/Core/tests/Unit/Report/EmptyMetadataProviderTest.php index 903ea0a36570..c255f6715ce0 100644 --- a/Core/tests/Unit/Report/EmptyMetadataProviderTest.php +++ b/Core/tests/Unit/Report/EmptyMetadataProviderTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Core\Tests\Unit\Report; use Google\Cloud\Core\Report\EmptyMetadataProvider; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -27,7 +27,7 @@ class EmptyMetadataProviderTest extends TestCase { private $metadataProvider; - public function setup() + public function set_up() { $this->metadataProvider = new EmptyMetadataProvider(); } diff --git a/Core/tests/Unit/Report/SimpleMetadataProviderTest.php b/Core/tests/Unit/Report/SimpleMetadataProviderTest.php index c9325b77c1b2..76b1060e678d 100644 --- a/Core/tests/Unit/Report/SimpleMetadataProviderTest.php +++ b/Core/tests/Unit/Report/SimpleMetadataProviderTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Core\Tests\Unit\Report; use Google\Cloud\Core\Report\SimpleMetadataProvider; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -37,7 +37,7 @@ class SimpleMetadataProviderTest extends TestCase private $labels = ['key' => 'value']; - public function setup() + public function set_up() { $this->metadataProvider = new SimpleMetadataProvider( $this->monitoredResource, diff --git a/Core/tests/Unit/RequestBuilderTest.php b/Core/tests/Unit/RequestBuilderTest.php index 35e6dff64688..aec69ba1738e 100644 --- a/Core/tests/Unit/RequestBuilderTest.php +++ b/Core/tests/Unit/RequestBuilderTest.php @@ -19,14 +19,17 @@ use Google\Cloud\Core\RequestBuilder; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class RequestBuilderTest extends TestCase { - public function setUp() + use ExpectException; + + public function set_up() { $this->builder = new RequestBuilder( Fixtures::SERVICE_FIXTURE(), @@ -136,11 +139,10 @@ public function basePaths() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testThrowsExceptionWithNonExistantMethod() { + $this->expectException('InvalidArgumentException'); + $this->builder->build('myResource', 'doesntExist'); } } diff --git a/Core/tests/Unit/RequestWrapperTest.php b/Core/tests/Unit/RequestWrapperTest.php index e9dff4391541..04561c048b93 100644 --- a/Core/tests/Unit/RequestWrapperTest.php +++ b/Core/tests/Unit/RequestWrapperTest.php @@ -29,12 +29,15 @@ use GuzzleHttp\Psr7\Response; use Prophecy\Argument; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class RequestWrapperTest extends TestCase { + use ExpectException; + const VERSION = 'v0.1'; private static $requestOptions = [ @@ -131,11 +134,10 @@ public function testGetKeyfile() $this->assertEquals($kf, $requestWrapper->keyFile()); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenRequestFails() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $requestWrapper = new RequestWrapper([ 'accessToken' => 'abc', 'httpHandler' => function ($request, $options = []) { @@ -146,11 +148,10 @@ public function testThrowsExceptionWhenRequestFails() $requestWrapper->send(new Request('GET', 'http://wwww.example.com')); } - /** - * @expectedException InvalidArgumentException - */ public function testThrowsExceptionWithInvalidCredentialsFetcher() { + $this->expectException('InvalidArgumentException'); + $credentialsFetcher = new \stdClass(); $requestWrapper = new RequestWrapper([ @@ -158,11 +159,10 @@ public function testThrowsExceptionWithInvalidCredentialsFetcher() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testThrowsExceptionWithInvalidCache() { + $this->expectException('InvalidArgumentException'); + $cache = new \stdClass(); $requestWrapper = new RequestWrapper([ @@ -299,11 +299,10 @@ public function testRequestUsesApiKeyInsteadOfAuthHeader() ); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenFetchingCredentialsFails() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $requestWrapper = new RequestWrapper([ 'authHttpHandler' => function ($request, $options = []) { throw new \Exception(); @@ -342,11 +341,10 @@ public function testExceptionMessageIsNotTruncatedWithGuzzle() } } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testThrowsBadRequestException() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $requestWrapper = new RequestWrapper([ 'httpHandler' => function ($request, $options = []) { throw new \Exception('', 400); @@ -358,11 +356,10 @@ public function testThrowsBadRequestException() ); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testThrowsNotFoundException() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $requestWrapper = new RequestWrapper([ 'httpHandler' => function ($request, $options = []) { throw new \Exception('', 404); @@ -374,11 +371,10 @@ public function testThrowsNotFoundException() ); } - /** - * @expectedException Google\Cloud\Core\Exception\ConflictException - */ public function testThrowsConflictException() { + $this->expectException('Google\Cloud\Core\Exception\ConflictException'); + $requestWrapper = new RequestWrapper([ 'httpHandler' => function ($request, $options = []) { throw new \Exception('', 409); @@ -390,11 +386,10 @@ public function testThrowsConflictException() ); } - /** - * @expectedException Google\Cloud\Core\Exception\ServerException - */ public function testThrowsServerException() { + $this->expectException('Google\Cloud\Core\Exception\ServerException'); + $requestWrapper = new RequestWrapper([ 'httpHandler' => function ($request, $options = []) { throw new \Exception('', 500); diff --git a/Core/tests/Unit/RestTraitTest.php b/Core/tests/Unit/RestTraitTest.php index 7d207090172b..f46b507c6ea2 100644 --- a/Core/tests/Unit/RestTraitTest.php +++ b/Core/tests/Unit/RestTraitTest.php @@ -24,20 +24,23 @@ use Google\Cloud\Core\Testing\TestHelpers; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group core */ class RestTraitTest extends TestCase { + use AssertStringContains; + private $implementation; private $requestBuilder; private $requestWrapper; - public function setUp() + public function set_up() { $this->implementation = $this->getObjectForTrait(RestTrait::class); $this->requestWrapper = $this->prophesize(RequestWrapper::class); @@ -100,7 +103,7 @@ public function testSendsRequestNotFoundWhitelisted() $msg = $e->getMessage(); } - $this->assertContains('NOTE: Error may be due to Whitelist Restriction.', $msg); + $this->assertStringContainsString('NOTE: Error may be due to Whitelist Restriction.', $msg); } public function testSendsRequestNotFoundNotWhitelisted() @@ -120,7 +123,7 @@ public function testSendsRequestNotFoundNotWhitelisted() $msg = $e->getMessage(); } - $this->assertNotContains('NOTE: Error may be due to Whitelist Restriction.', $msg); + $this->assertStringNotContainsString('NOTE: Error may be due to Whitelist Restriction.', $msg); } /** diff --git a/Core/tests/Unit/RetryDeciderTraitTest.php b/Core/tests/Unit/RetryDeciderTraitTest.php index f25fee01e1f2..ce32ba417bb5 100644 --- a/Core/tests/Unit/RetryDeciderTraitTest.php +++ b/Core/tests/Unit/RetryDeciderTraitTest.php @@ -22,7 +22,7 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -31,7 +31,7 @@ class RetryDeciderTraitTest extends TestCase { private $impl; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(RetryDeciderTrait::class); } diff --git a/Core/tests/Unit/ServicesNotFoundTest.php b/Core/tests/Unit/ServicesNotFoundTest.php index fb0523028b4f..a5417f09c905 100644 --- a/Core/tests/Unit/ServicesNotFoundTest.php +++ b/Core/tests/Unit/ServicesNotFoundTest.php @@ -19,18 +19,21 @@ use Google\Cloud\Core\ServiceBuilder; use Composer\Autoload\ClassLoader; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class ServicesNotFoundTest extends TestCase { + use ExpectException; + private static $previousAutoloadFunc; private static $newAutoloadFunc; private static $cloud; - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$cloud = new ServiceBuilder; foreach (spl_autoload_functions() as $function) { @@ -46,7 +49,7 @@ public static function setUpBeforeClass() } } - public static function tearDownAfterClass() + public static function tear_down_after_class() { spl_autoload_register(self::$previousAutoloadFunc); spl_autoload_unregister(self::$newAutoloadFunc); @@ -104,7 +107,8 @@ public function serviceBuilderMethods() */ public function testServicesNotFound($method) { - $this->setExpectedException(\Exception::class, sprintf( + $this->expectException(\Exception::class); + $this->expectExceptionMessage(sprintf( 'The google/cloud-%s package is missing and must be installed.', strtolower($method) )); diff --git a/Core/tests/Unit/SysvTraitTest.php b/Core/tests/Unit/SysvTraitTest.php index 5770450af118..3ee72d992559 100644 --- a/Core/tests/Unit/SysvTraitTest.php +++ b/Core/tests/Unit/SysvTraitTest.php @@ -19,14 +19,14 @@ use Google\Cloud\Core\SysvTrait; use Google\Cloud\Core\Testing\TestHelpers; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core */ class SysvTraitTest extends TestCase { - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(SysvTrait::class); } diff --git a/Core/tests/Unit/TimestampTest.php b/Core/tests/Unit/TimestampTest.php index 75c6e59071fe..8d192efc2c9b 100644 --- a/Core/tests/Unit/TimestampTest.php +++ b/Core/tests/Unit/TimestampTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Timestamp; use Google\Cloud\Core\TimeTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -32,7 +32,7 @@ class TimestampTest extends TestCase private $dt; private $ts; - public function setUp() + public function set_up() { $this->dt = new \DateTime(); $this->ts = new Timestamp($this->dt); diff --git a/Core/tests/Unit/Upload/MultipartUploaderTest.php b/Core/tests/Unit/Upload/MultipartUploaderTest.php index e5e6add72182..5b13b630671c 100644 --- a/Core/tests/Unit/Upload/MultipartUploaderTest.php +++ b/Core/tests/Unit/Upload/MultipartUploaderTest.php @@ -91,7 +91,8 @@ public function testStreamWithoutSizeDoesNotReceiveContentLengthHeader($stream, $requestWrapper->send( Argument::that( function (RequestInterface $request) use ($shouldContentLengthExist) { - return $request->hasHeader('Content-Length') === $shouldContentLengthExist; + $this->assertEquals($request->hasHeader('Content-Length'), $shouldContentLengthExist); + return true; } ), Argument::type('array') @@ -116,12 +117,14 @@ public function streamSizes() private function createStreamWithSizeOf($size) { - $stream = $this->getMockBuilder(Psr7\Stream::class) - ->setConstructorArgs([fopen('php://temp', 'r+')]) - ->setMethods(['getSize']) - ->getMock(); - $stream->method('getSize')->willReturn($size); + $stream = $this->prophesize(Psr7\Stream::class); + $stream->getSize() + ->willReturn($size); + $stream->isReadable() + ->willReturn(true); + $stream->isSeekable() + ->willReturn(true); - return $stream; + return $stream->reveal(); } } diff --git a/Core/tests/Unit/Upload/ResumableUploaderTest.php b/Core/tests/Unit/Upload/ResumableUploaderTest.php index 29d0b4586db3..7c35666ca1c0 100644 --- a/Core/tests/Unit/Upload/ResumableUploaderTest.php +++ b/Core/tests/Unit/Upload/ResumableUploaderTest.php @@ -25,7 +25,8 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -33,11 +34,13 @@ */ class ResumableUploaderTest extends TestCase { + use ExpectException; + private $requestWrapper; private $stream; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->stream = Utils::streamFor('abcd'); @@ -87,11 +90,10 @@ public function testUploadsDataWithCallback() $this->assertTrue($called); } - /** - * @expectedException InvalidArgumentException - */ public function testUploadsDataWithInvalidCallback() { + $this->expectException('InvalidArgumentException'); + $callback = 'foo'; $uploader = new ResumableUploader( @@ -171,11 +173,10 @@ public function testResumeFinishedUpload() ); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenAttemptsAsyncUpload() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $stream = $this->prophesize(StreamInterface::class); $uploader = new ResumableUploader( $this->requestWrapper->reveal(), @@ -186,11 +187,10 @@ public function testThrowsExceptionWhenAttemptsAsyncUpload() $uploader->uploadAsync(); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenResumingNonSeekableStream() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $stream = $this->prophesize(StreamInterface::class); $stream->isSeekable()->willReturn(false); $stream->getMetadata('uri')->willReturn('blah'); @@ -204,11 +204,10 @@ public function testThrowsExceptionWhenResumingNonSeekableStream() $uploader->resume('http://some-resume-uri.example.com'); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWithFailedUpload() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $resumeUriResponse = new Response(200, ['Location' => 'theResumeUri']); $this->requestWrapper->send( diff --git a/Core/tests/Unit/Upload/SignedUrlUploaderTest.php b/Core/tests/Unit/Upload/SignedUrlUploaderTest.php index 0f3c2beec45c..4125e31dfde2 100644 --- a/Core/tests/Unit/Upload/SignedUrlUploaderTest.php +++ b/Core/tests/Unit/Upload/SignedUrlUploaderTest.php @@ -25,7 +25,7 @@ use GuzzleHttp\Psr7\Utils; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -37,7 +37,7 @@ class SignedUrlUploaderTest extends TestCase private $stream; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->stream = Utils::streamFor('abcd'); diff --git a/Core/tests/Unit/Upload/StreamableUploaderTest.php b/Core/tests/Unit/Upload/StreamableUploaderTest.php index c079d084e07f..1444b8aa9519 100644 --- a/Core/tests/Unit/Upload/StreamableUploaderTest.php +++ b/Core/tests/Unit/Upload/StreamableUploaderTest.php @@ -25,7 +25,8 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core @@ -33,11 +34,13 @@ */ class StreamableUploaderTest extends TestCase { + use ExpectException; + private $requestWrapper; private $stream; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->stream = new BufferStream(16); @@ -120,11 +123,10 @@ public function testGetResumeUri() $this->assertEquals($resumeUri, $uploader->getResumeUri()); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWithFailedUpload() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $resumeUriResponse = new Response(200, ['Location' => 'theResumeUri']); $this->requestWrapper->send( @@ -172,11 +174,10 @@ public function testLastChunkSendsCorrectHeaders() $uploader->upload(); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testThrowsExceptionWhenAttemptsAsyncUpload() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $stream = $this->prophesize(StreamInterface::class); $uploader = new StreamableUploader( $this->requestWrapper->reveal(), diff --git a/Core/tests/Unit/UriTraitTest.php b/Core/tests/Unit/UriTraitTest.php index d5761d493152..34ec067ba8cb 100644 --- a/Core/tests/Unit/UriTraitTest.php +++ b/Core/tests/Unit/UriTraitTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Core\Tests\Unit; use Google\Cloud\Core\UriTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -27,7 +27,7 @@ class UriTraitTest extends TestCase { private $implementation; - public function setUp() + public function set_up() { $this->implementation = $this->getObjectForTrait(UriTrait::class); } diff --git a/Core/tests/Unit/ValidateTraitTest.php b/Core/tests/Unit/ValidateTraitTest.php index 57dd694c8e05..d3c90031d769 100644 --- a/Core/tests/Unit/ValidateTraitTest.php +++ b/Core/tests/Unit/ValidateTraitTest.php @@ -19,16 +19,19 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Core\ValidateTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group core */ class ValidateTraitTest extends TestCase { + use ExpectException; + private $stub; - public function setUp() + public function set_up() { $this->stub = TestHelpers::impl(ValidateTrait::class); } @@ -44,11 +47,10 @@ public function testValidateBatch() $this->stub->call('validateBatch', [$input, \stdClass::class]); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateBatchInvalidInput() { + $this->expectException('InvalidArgumentException'); + $input = [ (object)[], (object)[], diff --git a/Core/tests/Unit/WhitelistTraitTest.php b/Core/tests/Unit/WhitelistTraitTest.php index 0eebd01e7b2b..cd4a84cd8d85 100644 --- a/Core/tests/Unit/WhitelistTraitTest.php +++ b/Core/tests/Unit/WhitelistTraitTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Core\Exception\ServiceException; use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Core\WhitelistTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group core @@ -30,7 +30,7 @@ class WhitelistTraitTest extends TestCase { private $trait; - public function setUp() + public function set_up() { $this->trait = TestHelpers::impl(WhitelistTrait::class); } diff --git a/Core/unit-bootstrap.php b/Core/unit-bootstrap.php index b1f22b4ce7c8..4fc30215b3d5 100644 --- a/Core/unit-bootstrap.php +++ b/Core/unit-bootstrap.php @@ -8,5 +8,3 @@ \SebastianBergmann\Comparator\Factory::getInstance()->register(new MessageAwareArrayComparator()); \SebastianBergmann\Comparator\Factory::getInstance()->register(new ProtobufMessageComparator()); \SebastianBergmann\Comparator\Factory::getInstance()->register(new ProtobufGPBEmptyComparator()); - -PHPUnit_Framework_Error_Deprecated::$enabled = false; diff --git a/DataCatalog/composer.json b/DataCatalog/composer.json index 6e9e61a2d8fa..dceab77eacff 100644 --- a/DataCatalog/composer.json +++ b/DataCatalog/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/DataFusion/composer.json b/DataFusion/composer.json index 2761274fe027..8fe3c630c980 100644 --- a/DataFusion/composer.json +++ b/DataFusion/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/DataLabeling/composer.json b/DataLabeling/composer.json index 36dd7c595158..15328707eab2 100644 --- a/DataLabeling/composer.json +++ b/DataLabeling/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Dataflow/composer.json b/Dataflow/composer.json index 5fd6346d491e..608f06a58b72 100644 --- a/Dataflow/composer.json +++ b/Dataflow/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Dataplex/composer.json b/Dataplex/composer.json index 50512f0c9bd4..c711fa3f0b39 100644 --- a/Dataplex/composer.json +++ b/Dataplex/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Dataproc/composer.json b/Dataproc/composer.json index d93d55231f1f..d7def9bf9646 100644 --- a/Dataproc/composer.json +++ b/Dataproc/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Dataproc/tests/System/ClusterControllerClientTest.php b/Dataproc/tests/System/ClusterControllerClientTest.php index 3309241b450b..48f2219cbdb0 100644 --- a/Dataproc/tests/System/ClusterControllerClientTest.php +++ b/Dataproc/tests/System/ClusterControllerClientTest.php @@ -21,7 +21,7 @@ use Google\ApiCore\PagedListResponse; use Google\Cloud\Dataproc\V1\ClusterControllerClient; use Google\Cloud\Dataproc\V1\ListClustersResponse; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class ClusterControllerClientTest extends TestCase { @@ -34,7 +34,7 @@ class ClusterControllerClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -42,7 +42,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/DataprocMetastore/composer.json b/DataprocMetastore/composer.json index 5754d8801970..d8de1832a602 100644 --- a/DataprocMetastore/composer.json +++ b/DataprocMetastore/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Datastore/composer.json b/Datastore/composer.json index 15e6138d2053..e205ed11231d 100644 --- a/Datastore/composer.json +++ b/Datastore/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6" diff --git a/Datastore/phpunit-snippets.xml.dist b/Datastore/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Datastore/phpunit-snippets.xml.dist +++ b/Datastore/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Datastore/tests/Snippet/BlobTest.php b/Datastore/tests/Snippet/BlobTest.php index 0b44490f71b2..5badf7e3f1e7 100644 --- a/Datastore/tests/Snippet/BlobTest.php +++ b/Datastore/tests/Snippet/BlobTest.php @@ -29,7 +29,7 @@ class BlobTest extends SnippetTestCase private $value; private $blob; - public function setUp() + public function set_up() { $this->value = 'foo'; $this->blob = new Blob($this->value); diff --git a/Datastore/tests/Snippet/DatastoreClientTest.php b/Datastore/tests/Snippet/DatastoreClientTest.php index 69c80fd91535..e36feeb87ae0 100644 --- a/Datastore/tests/Snippet/DatastoreClientTest.php +++ b/Datastore/tests/Snippet/DatastoreClientTest.php @@ -34,12 +34,14 @@ use Google\Cloud\Datastore\ReadOnlyTransaction; use Google\Cloud\Datastore\Transaction; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group datastore */ class DatastoreClientTest extends SnippetTestCase { + use AssertIsType; use DatastoreOperationRefreshTrait; const PROJECT = 'example-project'; @@ -49,7 +51,7 @@ class DatastoreClientTest extends SnippetTestCase private $client; private $key; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(DatastoreClient::class, [], ['operation']); @@ -134,7 +136,7 @@ public function testKeys() $snippet->addLocal('datastore', $this->client); $res = $snippet->invoke('keys'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); $this->assertCount(10, $res->returnVal()); $this->assertInstanceOf(Key::class, $res->returnVal()[0]); $this->assertEquals('Person', $res->returnVal()[0]->keyObject()['path'][0]['kind']); @@ -147,7 +149,7 @@ public function testKeysWithAncestors() $res = $snippet->invoke('keys'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); $this->assertCount(3, $res->returnVal()); $this->assertInstanceOf(Key::class, $res->returnVal()[0]); diff --git a/Datastore/tests/Snippet/DatastoreSessionHandlerTest.php b/Datastore/tests/Snippet/DatastoreSessionHandlerTest.php index a4e1465b0f3f..4e784449b871 100644 --- a/Datastore/tests/Snippet/DatastoreSessionHandlerTest.php +++ b/Datastore/tests/Snippet/DatastoreSessionHandlerTest.php @@ -24,6 +24,7 @@ use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Datastore\DatastoreSessionHandler; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group datastore @@ -32,6 +33,7 @@ */ class DatastoreSessionHandlerTest extends SnippetTestCase { + use ExpectException; use DatastoreOperationRefreshTrait; const TRANSACTION = 'transaction-id'; @@ -39,9 +41,9 @@ class DatastoreSessionHandlerTest extends SnippetTestCase private $connection; private $client; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); // Since the tests in this class must run in isolation, they won't be // recognized as having been covered, and will cause a CI error. @@ -51,7 +53,7 @@ public static function setUpBeforeClass() self::snippetFromClass(DatastoreSessionHandler::class, 1); } - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(DatastoreClient::class, [], [ @@ -103,11 +105,10 @@ public function testClass() $this->assertEquals('Bob', $res->output()); } - /** - * @expectedException \RuntimeException - */ public function testClassErrorHandler() { + $this->expectException('\RuntimeException'); + $snippet = $this->snippetFromClass(DatastoreSessionHandler::class, 1); $snippet->replace('$datastore = new DatastoreClient();', ''); diff --git a/Datastore/tests/Snippet/EntityTest.php b/Datastore/tests/Snippet/EntityTest.php index 2a5c127bcc85..bc76615cec70 100644 --- a/Datastore/tests/Snippet/EntityTest.php +++ b/Datastore/tests/Snippet/EntityTest.php @@ -36,7 +36,7 @@ class EntityTest extends SnippetTestCase private $entity; private $key; - public function setUp() + public function set_up() { $this->options = [ 'cursor' => 'foo', diff --git a/Datastore/tests/Snippet/GeoPointTest.php b/Datastore/tests/Snippet/GeoPointTest.php index 3e169b68b7fb..092a28aa2f83 100644 --- a/Datastore/tests/Snippet/GeoPointTest.php +++ b/Datastore/tests/Snippet/GeoPointTest.php @@ -28,7 +28,7 @@ class GeoPointTest extends SnippetTestCase private $point; private $gp; - public function setUp() + public function set_up() { $this->point = ['latitude' => 123.45, 'longitude' => 543.21]; $this->gp = new GeoPoint($this->point['latitude'], $this->point['longitude']); diff --git a/Datastore/tests/Snippet/KeyTest.php b/Datastore/tests/Snippet/KeyTest.php index c84c138562bb..12cdd5a2f12b 100644 --- a/Datastore/tests/Snippet/KeyTest.php +++ b/Datastore/tests/Snippet/KeyTest.php @@ -21,15 +21,18 @@ use Google\Cloud\Datastore\Key; use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group datastore */ class KeyTest extends SnippetTestCase { + use ExpectException; + private $key; - public function setUp() + public function set_up() { $this->key = new Key('my-awesome-project'); } @@ -62,11 +65,10 @@ public function testClassComplexPath() $this->assertCount(3, $res->returnVal()->path()); } - /** - * @expectedException InvalidArgumentException - */ public function testClassErrorOnAppend() { + $this->expectException('InvalidArgumentException'); + $ds = $this->prophesize(DatastoreClient::class); $ds->key(Argument::any(), Argument::any()) ->will(function ($args) { diff --git a/Datastore/tests/Snippet/Query/GqlQueryTest.php b/Datastore/tests/Snippet/Query/GqlQueryTest.php index cc4c2c9decfb..730fbbb0138f 100644 --- a/Datastore/tests/Snippet/Query/GqlQueryTest.php +++ b/Datastore/tests/Snippet/Query/GqlQueryTest.php @@ -37,7 +37,7 @@ class GqlQueryTest extends SnippetTestCase private $connection; private $operation; - public function setUp() + public function set_up() { $this->datastore = TestHelpers::stub(DatastoreClient::class, [], ['operation']); $this->connection = $this->prophesize(ConnectionInterface::class); @@ -166,7 +166,7 @@ public function provideCursor() private function provideSnippets($name) { - parent::setUpBeforeClass(); + parent::set_up_before_class(); return [ [$this->snippetFromMethod(DatastoreClient::class, 'gqlQuery', $name)], diff --git a/Datastore/tests/Snippet/Query/QueryTest.php b/Datastore/tests/Snippet/Query/QueryTest.php index 4025a0fe1c7c..437007297ba1 100644 --- a/Datastore/tests/Snippet/Query/QueryTest.php +++ b/Datastore/tests/Snippet/Query/QueryTest.php @@ -38,7 +38,7 @@ class QueryTest extends SnippetTestCase private $operation; private $query; - public function setUp() + public function set_up() { $mapper = new EntityMapper('my-awesome-project', true, false); diff --git a/Datastore/tests/Snippet/ReadOnlyTransactionTest.php b/Datastore/tests/Snippet/ReadOnlyTransactionTest.php index 194692783c66..54626ffd1985 100644 --- a/Datastore/tests/Snippet/ReadOnlyTransactionTest.php +++ b/Datastore/tests/Snippet/ReadOnlyTransactionTest.php @@ -45,7 +45,7 @@ class ReadOnlyTransactionTest extends SnippetTestCase private $client; private $key; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Datastore/tests/Snippet/TransactionTest.php b/Datastore/tests/Snippet/TransactionTest.php index ccc02a59577c..c2477d5dc037 100644 --- a/Datastore/tests/Snippet/TransactionTest.php +++ b/Datastore/tests/Snippet/TransactionTest.php @@ -45,7 +45,7 @@ class TransactionTest extends SnippetTestCase private $client; private $key; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Datastore/tests/System/AllocateKeyTest.php b/Datastore/tests/System/AllocateKeyTest.php index 42b094d25f28..62b12c304f40 100644 --- a/Datastore/tests/System/AllocateKeyTest.php +++ b/Datastore/tests/System/AllocateKeyTest.php @@ -18,6 +18,7 @@ namespace Google\Cloud\Datastore\Tests\System; use Google\Cloud\Datastore\DatastoreClient; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group datastore @@ -25,6 +26,8 @@ */ class AllocateKeyTest extends DatastoreTestCase { + use AssertIsType; + /** * @dataProvider clientProvider */ @@ -34,7 +37,7 @@ public function testAllocateId(DatastoreClient $client) $key = $client->key($kind); $path = $client->allocateId($key)->path()[0]; - $this->assertInternalType('numeric', $path['id']); + $this->assertIsNumeric($path['id']); $this->assertEquals($kind, $path['kind']); } @@ -49,7 +52,7 @@ public function testAllocateIds(DatastoreClient $client) foreach ($allocatedKeys as $key) { $path = $key->path()[0]; - $this->assertInternalType('numeric', $path['id']); + $this->assertIsNumeric($path['id']); $this->assertEquals($kind, $path['kind']); } } diff --git a/Datastore/tests/System/DatastoreTestCase.php b/Datastore/tests/System/DatastoreTestCase.php index d65594c0f237..ce9bfb91950e 100644 --- a/Datastore/tests/System/DatastoreTestCase.php +++ b/Datastore/tests/System/DatastoreTestCase.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\ExponentialBackoff; use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Core\Testing\System\DeletionQueue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Datastore does not use the default deletion queue. Because of the way @@ -37,7 +37,7 @@ class DatastoreTestCase extends TestCase protected static $localDeletionQueue; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; @@ -80,7 +80,7 @@ public static function tearDownFixtures() public function clientProvider() { - self::setupBeforeClass(); + self::set_up_before_class(); return [ 'restClient' => [self::$restClient], diff --git a/Datastore/tests/System/QueryResultPaginationTest.php b/Datastore/tests/System/QueryResultPaginationTest.php index 96d29069b4f2..ad08e22c44d3 100644 --- a/Datastore/tests/System/QueryResultPaginationTest.php +++ b/Datastore/tests/System/QueryResultPaginationTest.php @@ -30,9 +30,9 @@ class QueryResultPaginationTest extends DatastoreTestCase private static $parentKey; private static $testKind; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); static $setUp = false; if ($setUp) { return; @@ -67,9 +67,9 @@ public static function setUpBeforeClass() $setUp = true; } - public static function tearDownAfterClass() + public static function tear_down_after_class() { - self::setUpBeforeClass(); + self::set_up_before_class(); $client = self::$restClient; $q = $client->query() diff --git a/Datastore/tests/System/RunQueryTest.php b/Datastore/tests/System/RunQueryTest.php index bc1715497be1..4666128511ba 100644 --- a/Datastore/tests/System/RunQueryTest.php +++ b/Datastore/tests/System/RunQueryTest.php @@ -50,9 +50,9 @@ class RunQueryTest extends DatastoreTestCase ] ]; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$ancestor = self::$restClient->key(self::$kind, 'Grandpa Frank'); $key1 = self::$restClient->key(self::$kind, 'Frank'); $key1->ancestorKey(self::$ancestor); diff --git a/Datastore/tests/Unit/Connection/GrpcTest.php b/Datastore/tests/Unit/Connection/GrpcTest.php index 206d6aef7fc1..f662c6d29822 100644 --- a/Datastore/tests/Unit/Connection/GrpcTest.php +++ b/Datastore/tests/Unit/Connection/GrpcTest.php @@ -37,7 +37,8 @@ use Google\Cloud\Datastore\V1\ReadOptions\ReadConsistency; use Google\Cloud\Datastore\V1\TransactionOptions; use Google\Protobuf\NullValue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Prophecy\Argument; /** @@ -46,6 +47,7 @@ */ class GrpcTest extends TestCase { + use ExpectException; use GrpcTestTrait; use GrpcTrait; @@ -55,7 +57,7 @@ class GrpcTest extends TestCase private $serializer; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -507,10 +509,11 @@ public function propertyFilters() /** * @dataProvider invalidFilters - * @expectedException \InvalidArgumentException */ public function testInvalidFilter($filter) { + $this->expectException('InvalidArgumentException'); + return $this->testQueryPropertyFilters($filter); } diff --git a/Datastore/tests/Unit/Connection/RestTest.php b/Datastore/tests/Unit/Connection/RestTest.php index 5b69227459e5..1810333a8165 100644 --- a/Datastore/tests/Unit/Connection/RestTest.php +++ b/Datastore/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Datastore\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Datastore/tests/Unit/DatastoreClientTest.php b/Datastore/tests/Unit/DatastoreClientTest.php index a58ec299ac36..2a47ef34be8b 100644 --- a/Datastore/tests/Unit/DatastoreClientTest.php +++ b/Datastore/tests/Unit/DatastoreClientTest.php @@ -34,7 +34,8 @@ use Google\Cloud\Datastore\Query\QueryInterface; use Google\Cloud\Datastore\ReadOnlyTransaction; use Google\Cloud\Datastore\Transaction; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Prophecy\Argument; /** @@ -44,6 +45,7 @@ class DatastoreClientTest extends TestCase { use DatastoreOperationRefreshTrait; + use ExpectException; use GrpcTestTrait; const PROJECT = 'example-project'; @@ -52,7 +54,7 @@ class DatastoreClientTest extends TestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(DatastoreClient::class, [ @@ -398,11 +400,10 @@ public function partialKeyMutationsProvider() }); } - /** - * @expectedException \DomainException - */ public function testSingleMutationConflict() { + $this->expectException('DomainException'); + $this->connection->commit(Argument::any()) ->shouldBeCalled() ->willReturn([ diff --git a/Datastore/tests/Unit/DatastoreSessionHandlerTest.php b/Datastore/tests/Unit/DatastoreSessionHandlerTest.php index 4423bcc68c52..7525ca8b441d 100644 --- a/Datastore/tests/Unit/DatastoreSessionHandlerTest.php +++ b/Datastore/tests/Unit/DatastoreSessionHandlerTest.php @@ -26,20 +26,25 @@ use Google\Cloud\Datastore\Transaction; use InvalidArgumentException; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group datastore */ class DatastoreSessionHandlerTest extends TestCase { + use AssertIsType; + use ExpectException; + const KIND = 'PHPSESSID'; const NAMESPACE_ID = 'sessions'; private $datastore; private $transaction; - public function setUp() + public function set_up() { $this->datastore = $this->prophesize(DatastoreClient::class); $this->transaction = $this->prophesize(Transaction::class); @@ -57,11 +62,10 @@ public function testOpen() $this->assertTrue($ret); } - /** - * @expectedException InvalidArgumentException - */ public function testOpenNotAllowed() { + $this->expectException('InvalidArgumentException'); + $this->datastore->transaction() ->shouldNotBeCalled() ->willReturn($this->transaction->reveal()); @@ -71,11 +75,10 @@ public function testOpenNotAllowed() $datastoreSessionHandler->open('/tmp/sessions', self::KIND); } - /** - * @expectedException InvalidArgumentException - */ public function testOpenReserved() { + $this->expectException('InvalidArgumentException'); + $this->datastore->transaction() ->shouldNotBeCalled() ->willReturn($this->transaction->reveal()); @@ -117,11 +120,10 @@ public function testReadNothing() $this->assertEquals('', $ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testReadWithException() { + $this->expectException('PHPUnit\Framework\Error\Warning'); + $this->datastore->transaction() ->shouldBeCalledTimes(1) ->willReturn($this->transaction->reveal()); @@ -194,7 +196,7 @@ public function testWrite() ->will(function ($args) use ($that, $key, $entity) { $that->assertEquals($key, $args[0]); $that->assertEquals('sessiondata', $args[1]['data']); - $that->assertInternalType('int', $args[1]['t']); + $that->assertIsInt($args[1]['t']); $that->assertGreaterThanOrEqual($args[1]['t'], time()); // 2 seconds grace period should be enough $that->assertLessThanOrEqual(2, time() - $args[1]['t']); @@ -210,11 +212,10 @@ public function testWrite() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testWriteWithException() { + $this->expectException('PHPUnit\Framework\Error\Warning'); + $data = 'sessiondata'; $key = new Key('projectid'); $key->pathElement(self::KIND, 'sessionid'); @@ -239,7 +240,7 @@ public function testWriteWithException() ->will(function ($args) use ($that, $key, $entity) { $that->assertEquals($key, $args[0]); $that->assertEquals('sessiondata', $args[1]['data']); - $that->assertInternalType('int', $args[1]['t']); + $that->assertIsInt($args[1]['t']); $that->assertGreaterThanOrEqual($args[1]['t'], time()); // 2 seconds grace period should be enough $that->assertLessThanOrEqual(2, time() - $args[1]['t']); @@ -284,7 +285,7 @@ public function testWriteWithEntityOptions() ->will(function ($args) use ($that, $key, $entity) { $that->assertEquals($key, $args[0]); $that->assertEquals('sessiondata', $args[1]['data']); - $that->assertInternalType('int', $args[1]['t']); + $that->assertIsInt($args[1]['t']); $that->assertGreaterThanOrEqual($args[1]['t'], time()); // 2 seconds grace period should be enough $that->assertLessThanOrEqual(2, time() - $args[1]['t']); @@ -330,7 +331,7 @@ public function testWriteWithEmptyEntityOptions() ->will(function ($args) use ($that, $key, $entity) { $that->assertEquals($key, $args[0]); $that->assertEquals('sessiondata', $args[1]['data']); - $that->assertInternalType('int', $args[1]['t']); + $that->assertIsInt($args[1]['t']); $that->assertGreaterThanOrEqual($args[1]['t'], time()); // 2 seconds grace period should be enough $that->assertLessThanOrEqual(2, time() - $args[1]['t']); @@ -350,10 +351,11 @@ public function testWriteWithEmptyEntityOptions() /** * @dataProvider invalidEntityOptions - * @expectedException InvalidArgumentException */ public function testInvalidEntityOptions($datastoreSessionHandlerOptions) { + $this->expectException('InvalidArgumentException'); + new DatastoreSessionHandler( $this->datastore->reveal(), DatastoreSessionHandler::DEFAULT_GC_LIMIT, @@ -401,11 +403,10 @@ public function testDestroy() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testDestroyWithException() { + $this->expectException('PHPUnit\Framework\Error\Warning'); + $key = new Key('projectid'); $key->pathElement(self::KIND, 'sessionid'); $this->transaction->delete($key) @@ -470,7 +471,7 @@ public function testGc() ->will(function ($args) use ($that, $query) { $that->assertEquals('t', $args[0]); $that->assertEquals('<', $args[1]); - $that->assertInternalType('int', $args[2]); + $that->assertIsInt($args[2]); $diff = time() - $args[2]; // 2 seconds grace period should be enough $that->assertLessThanOrEqual(102, $diff); @@ -521,11 +522,10 @@ public function testGc() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testGcWithException() { + $this->expectException('PHPUnit\Framework\Error\Warning'); + $key1 = new Key('projectid'); $key1->pathElement(self::KIND, 'sessionid1'); $key2 = new Key('projectid'); @@ -546,7 +546,7 @@ public function testGcWithException() ->will(function ($args) use ($that, $query) { $that->assertEquals('t', $args[0]); $that->assertEquals('<', $args[1]); - $that->assertInternalType('int', $args[2]); + $that->assertIsInt($args[2]); $diff = time() - $args[2]; // 2 seconds grace period should be enough $that->assertLessThanOrEqual(102, $diff); diff --git a/Datastore/tests/Unit/DatastoreTraitTest.php b/Datastore/tests/Unit/DatastoreTraitTest.php index 458d4be1c801..2d9f842cf08e 100644 --- a/Datastore/tests/Unit/DatastoreTraitTest.php +++ b/Datastore/tests/Unit/DatastoreTraitTest.php @@ -22,16 +22,19 @@ use Google\Cloud\Datastore\DatastoreTrait; use Google\Cloud\Datastore\Key; use Google\Cloud\Datastore\Transaction; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group datastore */ class DatastoreTraitTest extends TestCase { + use AssertIsType; + private $stub; - public function setUp() + public function set_up() { $this->stub = TestHelpers::impl(DatastoreTrait::class); } @@ -42,7 +45,7 @@ public function testPartitionId() 'foo', 'bar' ]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertEquals('foo', $res['projectId']); $this->assertEquals('bar', $res['namespaceId']); } diff --git a/Datastore/tests/Unit/EntityMapperTest.php b/Datastore/tests/Unit/EntityMapperTest.php index 083f0e712997..c1c9f787f2d1 100644 --- a/Datastore/tests/Unit/EntityMapperTest.php +++ b/Datastore/tests/Unit/EntityMapperTest.php @@ -25,7 +25,9 @@ use Google\Cloud\Datastore\EntityMapper; use Google\Cloud\Datastore\GeoPoint; use Google\Cloud\Datastore\Key; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group datastore @@ -33,12 +35,15 @@ */ class EntityMapperTest extends TestCase { + use AssertIsType; + use ExpectException; + const DATE_FORMAT = 'Y-m-d\TH:i:s.uP'; const DATE_FORMAT_NO_MS = 'Y-m-d\TH:i:sP'; private $mapper; - public function setUp() + public function set_up() { $this->mapper = new EntityMapper('foo', true, false); } @@ -250,7 +255,7 @@ public function testResponseToPropertiesEntityValueCustomTypeNestedPropertyUsesD $res = $this->mapper->responseToEntityProperties($data, SampleEntity::class)['properties']; $this->assertInstanceOf(SampleEntity::class, $res['foo']); - $this->assertInternalType('array', $res['foo']['bar']); + $this->assertIsArray($res['foo']['bar']); } public function testResponseToPropertiesEntityNestedValueCustomType() @@ -287,11 +292,10 @@ public function testResponseToPropertiesEntityNestedValueCustomType() $this->assertEquals('bar', $res['foo']['nest']['nest']['foo']); } - /** - * @expectedException \InvalidArgumentException - */ public function testResponseToPropertiesEntityValueInvalidType() { + $this->expectException('\InvalidArgumentException'); + $data = [ 'foo' => [ 'entityValue' => [ @@ -307,11 +311,10 @@ public function testResponseToPropertiesEntityValueInvalidType() $this->mapper->responseToEntityProperties($data, static::class); } - /** - * @expectedException \InvalidArgumentException - */ public function testResponseToPropertiesEntityValueInvalidMappingType() { + $this->expectException('\InvalidArgumentException'); + $data = [ 'invalid' => [ 'entityValue' => [ @@ -349,11 +352,10 @@ public function testResponseToPropertiesArrayValue() $this->assertEquals(['a','b','c'], $res['foo']); } - /** - * @expectedException RuntimeException - */ public function testResponseToPropertiesNoValuePresent() { + $this->expectException('RuntimeException'); + $data = [ 'foo' => [ 'meaning' => 1 @@ -542,7 +544,7 @@ public function testConvertValueEntityWithoutKey() ]; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertEquals('test', $res['prop']); } @@ -559,7 +561,7 @@ public function testConvertValueEntityWithoutKeyExcludes() ]; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertEquals('test', $res['prop']); $this->assertEquals(['prop'], $res[Entity::EXCLUDE_FROM_INDEXES]); } @@ -570,7 +572,7 @@ public function testConvertValueDouble() $val = 1.1; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('float', $res); + $this->assertIsFloat($res); $this->assertEquals(1.1, $res); } @@ -580,7 +582,7 @@ public function testConvertValueDoubleWithCast() $val = 1; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('float', $res); + $this->assertIsFloat($res); $this->assertEquals((float)1, $res); } @@ -623,11 +625,10 @@ public function unencoded() ]; } - /** - * @expectedException RuntimeException - */ public function testConvertValueInvalidType() { + $this->expectException('RuntimeException'); + $type = 'fooBarValue'; $val = 'nothanks'; $this->mapper->convertValue($type, $val); @@ -644,7 +645,7 @@ public function testArrayValue() ]; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertEquals(['foo', 'bar'], $res); } @@ -654,7 +655,7 @@ public function testEmptyArrayValue() $val = []; $res = $this->mapper->convertValue($type, $val); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertEquals([], $res); } @@ -840,11 +841,10 @@ public function testObjectPropertyEntity() $this->assertEquals('val', $res['entityValue']['properties']['key']['stringValue']); } - /** - * @expectedException InvalidArgumentException - */ public function testObjectPropertyInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->mapper->valueObject($this); } diff --git a/Datastore/tests/Unit/EntityTest.php b/Datastore/tests/Unit/EntityTest.php index c1283b757aa4..1afc73a22752 100644 --- a/Datastore/tests/Unit/EntityTest.php +++ b/Datastore/tests/Unit/EntityTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Datastore\Entity; use Google\Cloud\Datastore\EntityMapper; use Google\Cloud\Datastore\Key; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group datastore @@ -30,7 +30,7 @@ class EntityTest extends TestCase private $key; private $mapper; - public function setUp() + public function set_up() { $this->key = new Key('foo', ['path' => [ ['kind' => 'kind', 'name' => 'name'] diff --git a/Datastore/tests/Unit/KeyTest.php b/Datastore/tests/Unit/KeyTest.php index edd228f5cc96..6e174c9ffc16 100644 --- a/Datastore/tests/Unit/KeyTest.php +++ b/Datastore/tests/Unit/KeyTest.php @@ -19,12 +19,15 @@ use Google\Cloud\Datastore\Key; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group datastore */ class KeyTest extends TestCase { + use ExpectException; + public function testWithInitialPath() { $key = new Key('foo', [ @@ -60,11 +63,10 @@ public function testPathElement() $this->assertEquals(['kind' => 'foo', 'name' => 'bar'], $key->keyObject()['path'][0]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidPathElementAddition() { + $this->expectException('InvalidArgumentException'); + $key = new Key('foo', [ 'path' => [ ['kind' => 'thing'] @@ -114,11 +116,10 @@ public function testAncestorKey() $this->assertEquals($path, $expected); } - /** - * @expectedException InvalidArgumentException - */ public function testAncestorKeyIncompletePath() { + $this->expectException('InvalidArgumentException'); + $ancestor = $this->prophesize(Key::class); $ancestor->state()->willReturn(Key::STATE_INCOMPLETE); @@ -137,11 +138,10 @@ public function testPathElementForceType() $this->assertEquals(['kind' => 'Robots', 'id' => '1000'], $key->keyObject()['path'][1]); } - /** - * @expectedException InvalidArgumentException - */ public function testPathElementInvalidIdentifierType() { + $this->expectException('InvalidArgumentException'); + $key = new Key('foo'); $key->pathElement('Robots', '1000', ['identifierType' => 'nothanks']); } @@ -155,11 +155,10 @@ public function testNormalizedPath() $this->assertEquals([['kind' => 'foo', 'id' => 1]], $key->path()); } - /** - * @expectedException InvalidArgumentException - */ public function testMissingKind() { + $this->expectException('InvalidArgumentException'); + $key = new Key('foo', [ 'path' => [ ['id' => '1'] @@ -167,11 +166,10 @@ public function testMissingKind() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testElementMissingIdentifier() { + $this->expectException('InvalidArgumentException'); + $key = new Key('foo', [ 'path' => [ ['kind' => 'foo'], diff --git a/Datastore/tests/Unit/OperationTest.php b/Datastore/tests/Unit/OperationTest.php index 35c23ba0100f..85f80a8c439b 100644 --- a/Datastore/tests/Unit/OperationTest.php +++ b/Datastore/tests/Unit/OperationTest.php @@ -27,7 +27,9 @@ use Google\Cloud\Datastore\Query\GqlQuery; use Google\Cloud\Datastore\Query\Query; use Google\Cloud\Datastore\Query\QueryInterface; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -36,13 +38,16 @@ */ class OperationTest extends TestCase { + use AssertIsType; + use ExpectException; + const PROJECT = 'example-project'; const NAMESPACEID = 'namespace-id'; private $operation; private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->operation = TestHelpers::stub(Operation::class, [ @@ -109,11 +114,10 @@ public function testKeysNumberCopy() $this->assertNull($keys[1]->pathEndIdentifier()); } - /** - * @expectedException InvalidArgumentException - */ public function testKeysNumberZero() { + $this->expectException('InvalidArgumentException'); + $this->operation->keys('Foo', [ 'number' => 0 ]); @@ -171,11 +175,10 @@ public function testEntityWithKind() $this->assertEquals('Foo', $e->key()->pathEnd()['kind']); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidKeyType() { + $this->expectException('InvalidArgumentException'); + $this->operation->entity(1); } @@ -188,11 +191,10 @@ public function testEntityCustomClass() $this->assertInstanceOf(SampleEntity::class, $e); } - /** - * @expectedException InvalidArgumentException - */ public function testEntityCustomClassInvalidType() { + $this->expectException('InvalidArgumentException'); + $e = $this->operation->entity('Foo', [], [ 'className' => Operation::class ]); @@ -221,11 +223,10 @@ public function testAllocateIds() $this->assertEquals($res[0]->path()[0]['id'], $id); } - /** - * @expectedException InvalidArgumentException - */ public function testAllocateIdsNamedKey() { + $this->expectException('InvalidArgumentException'); + $key = $this->operation->key('foo', 'Bar'); $this->operation->allocateIds([$key]); @@ -243,7 +244,7 @@ public function testLookup() $res = $this->operation->lookup([$key]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); } public function testLookupFound() @@ -258,7 +259,7 @@ public function testLookupFound() $key = $this->operation->key('Kind', 'ID'); $res = $this->operation->lookup([$key]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertTrue(isset($res['found']) && is_array($res['found'])); $this->assertInstanceOf(Entity::class, $res['found'][0]); @@ -281,7 +282,7 @@ public function testLookupMissing() $res = $this->operation->lookup([$key]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertTrue(isset($res['missing']) && is_array($res['missing'])); $this->assertInstanceOf(Key::class, $res['missing'][0]); @@ -301,7 +302,7 @@ public function testLookupDeferred() $res = $this->operation->lookup([$key]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertTrue(isset($res['deferred']) && is_array($res['deferred'])); $this->assertInstanceOf(Key::class, $res['deferred'][0]); } @@ -442,11 +443,10 @@ public function testLookupWithSortAndMissingKey() $this->assertEquals($keys[10]->path()[0]['id'], $found[9]->key()->path()[0]['id']); } - /** - * @expectedException InvalidArgumentException - */ public function testLookupInvalidKey() { + $this->expectException('InvalidArgumentException'); + $key = $this->operation->key('Foo'); $this->operation->lookup([$key]); @@ -734,11 +734,10 @@ public function testMutateWithKey() $this->operation->commit([$mutation]); } - /** - * @expectedException InvalidArgumentException - */ public function testMutateInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->operation->mutation('foo', (object)[], \stdClass::class); } @@ -758,11 +757,10 @@ public function testCheckOverwriteWithFlagEnabled() $this->operation->checkOverwrite([$e->reveal()], true); } - /** - * @expectedException InvalidArgumentException - */ public function testCheckOverwriteWithException() { + $this->expectException('InvalidArgumentException'); + $e = $this->prophesize(Entity::class); $e->populatedByService()->willReturn(false); $e->key()->willReturn('foo'); @@ -833,11 +831,10 @@ public function testMapEntityResultArrayOfClassNames() $this->assertInstanceOf(SampleEntity::class, $entity['found'][0]); } - /** - * @expectedException InvalidArgumentException - */ public function testMapEntityResultArrayOfClassNamesMissingKindMapItem() { + $this->expectException('InvalidArgumentException'); + $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_FIXTURE()), true); $this->connection->lookup(Argument::type('array')) @@ -897,11 +894,10 @@ public function testReadConsistencyInReadOptions() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidBatchType() { + $this->expectException('InvalidArgumentException'); + $this->operation->lookup(['foo']); } } diff --git a/Datastore/tests/Unit/Query/GqlQueryTest.php b/Datastore/tests/Unit/Query/GqlQueryTest.php index 025785406c4d..8e9dc7891f2d 100644 --- a/Datastore/tests/Unit/Query/GqlQueryTest.php +++ b/Datastore/tests/Unit/Query/GqlQueryTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Datastore\Cursor; use Google\Cloud\Datastore\EntityMapper; use Google\Cloud\Datastore\Query\GqlQuery; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group datastore @@ -29,7 +29,7 @@ class GqlQueryTest extends TestCase { private $mapper; - public function setUp() + public function set_up() { $this->mapper = new EntityMapper('foo', true, false); } diff --git a/Datastore/tests/Unit/Query/QueryTest.php b/Datastore/tests/Unit/Query/QueryTest.php index ba7585980546..216347fd087a 100644 --- a/Datastore/tests/Unit/Query/QueryTest.php +++ b/Datastore/tests/Unit/Query/QueryTest.php @@ -20,17 +20,20 @@ use Google\Cloud\Datastore\EntityMapper; use Google\Cloud\Datastore\Key; use Google\Cloud\Datastore\Query\Query; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group datastore */ class QueryTest extends TestCase { + use ExpectException; + private $query; private $mapper; - public function setUp() + public function set_up() { $this->mapper = new EntityMapper('foo', true, false); $this->query = new Query($this->mapper); @@ -152,11 +155,10 @@ public function testFilterCustomOperator() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testFilterInvalidOperator() { + $this->expectException('InvalidArgumentException'); + $this->query->filter('propname', 'foo', 12); } diff --git a/Datastore/tests/Unit/TransactionTest.php b/Datastore/tests/Unit/TransactionTest.php index 5017422e0550..2d8477cd3dcb 100644 --- a/Datastore/tests/Unit/TransactionTest.php +++ b/Datastore/tests/Unit/TransactionTest.php @@ -27,7 +27,7 @@ use Google\Cloud\Datastore\Query\QueryInterface; use Google\Cloud\Datastore\ReadOnlyTransaction; use Google\Cloud\Datastore\Transaction; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -49,7 +49,7 @@ class TransactionTest extends TestCase private $key; private $entity; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/DatastoreAdmin/composer.json b/DatastoreAdmin/composer.json index 7c5f5fab9be7..b262a90640a6 100644 --- a/DatastoreAdmin/composer.json +++ b/DatastoreAdmin/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Debugger/composer.json b/Debugger/composer.json index 7264475e5806..cd45a4d5759a 100644 --- a/Debugger/composer.json +++ b/Debugger/composer.json @@ -11,7 +11,8 @@ "psr/log": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Debugger/phpunit-snippets.xml.dist b/Debugger/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Debugger/phpunit-snippets.xml.dist +++ b/Debugger/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Debugger/tests/Snippet/AgentTest.php b/Debugger/tests/Snippet/AgentTest.php index af249a1c154f..66f5a7599d0c 100644 --- a/Debugger/tests/Snippet/AgentTest.php +++ b/Debugger/tests/Snippet/AgentTest.php @@ -29,7 +29,7 @@ class AgentTest extends SnippetTestCase { private $storage; - public function setUp() + public function set_up() { $this->storage = $this->prophesize(BreakpointStorageInterface::class); } diff --git a/Debugger/tests/Snippet/DaemonTest.php b/Debugger/tests/Snippet/DaemonTest.php index c36e9385e9d2..7799f92ae8eb 100644 --- a/Debugger/tests/Snippet/DaemonTest.php +++ b/Debugger/tests/Snippet/DaemonTest.php @@ -33,7 +33,7 @@ class DaemonTest extends SnippetTestCase private $debuggee; private $storage; - public function setUp() + public function set_up() { $this->client = $this->prophesize(DebuggerClient::class); $this->debuggee = $this->prophesize(Debuggee::class); diff --git a/Debugger/tests/Snippet/DebuggeeTest.php b/Debugger/tests/Snippet/DebuggeeTest.php index c6cd1553d2a9..e54a7a3352c6 100644 --- a/Debugger/tests/Snippet/DebuggeeTest.php +++ b/Debugger/tests/Snippet/DebuggeeTest.php @@ -30,7 +30,7 @@ class DebuggeeTest extends SnippetTestCase { private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/Debugger/tests/Snippet/DebuggerClientTest.php b/Debugger/tests/Snippet/DebuggerClientTest.php index 9ac3251fd1bc..b21b6c514b4d 100644 --- a/Debugger/tests/Snippet/DebuggerClientTest.php +++ b/Debugger/tests/Snippet/DebuggerClientTest.php @@ -32,7 +32,7 @@ class DebuggerClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(DebuggerClient::class); diff --git a/Debugger/tests/System/BasicTest.php b/Debugger/tests/System/BasicTest.php index 3aaef23aca45..089c72b84ca5 100644 --- a/Debugger/tests/System/BasicTest.php +++ b/Debugger/tests/System/BasicTest.php @@ -21,12 +21,15 @@ use Google\Cloud\Debugger\Debuggee; use Google\Cloud\Debugger\DebuggerClient; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group debugger */ class BasicTest extends TestCase { + use AssertIsType; + /** * @dataProvider transports */ @@ -35,7 +38,7 @@ public function testCanListDebuggees($transport) $debuggerClient = $this->getClient($transport); $debuggees = $debuggerClient->debuggees(); - $this->assertInternalType('array', $debuggees); + $this->assertIsArray($debuggees); $this->assertContainsOnlyInstancesOf( Debuggee::class, $debuggees @@ -65,7 +68,7 @@ public function testRegisterSetUseBreakpoint($transport) // Fetch the list of breakpoints $breakpoints = $debuggee->breakpoints(); - $this->assertInternalType('array', $breakpoints); + $this->assertIsArray($breakpoints); $this->assertContainsOnlyInstancesOf( Breakpoint::class, $breakpoints diff --git a/Debugger/tests/System/E2ETest.php b/Debugger/tests/System/E2ETest.php index 83a4f4cd2cca..f5d9c78e10cb 100644 --- a/Debugger/tests/System/E2ETest.php +++ b/Debugger/tests/System/E2ETest.php @@ -22,7 +22,8 @@ use Google\Cloud\TestUtils\EventuallyConsistentTestTrait; use Google\Cloud\TestUtils\AppEngineDeploymentTrait; use GuzzleHttp\Client; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * The test deploys the sample app contained in the app folder to Google App @@ -41,6 +42,7 @@ class E2ETest extends TestCase protected $debuggeeId; protected $httpClient; + use AssertStringContains; use AppEngineDeploymentTrait; use EventuallyConsistentTestTrait; @@ -50,7 +52,7 @@ public static function beforeDeploy() self::$gcloudWrapper->setDir(implode(DIRECTORY_SEPARATOR, [__DIR__, 'app'])); } - public function setUp() + public function set_up() { $url = self::$gcloudWrapper->getBaseUrl(); $this->httpClient = new Client(['base_uri' => $url]); @@ -64,7 +66,7 @@ public function setUp() }, 5, true); } - public static function tearDownAfterClass() + public static function tear_down_after_class() { self::deleteApp(); } @@ -117,7 +119,7 @@ public function testWithFullPath() $resp = $this->httpClient->get('hello/full'); $this->assertEquals('200', $resp->getStatusCode(), 'hello/full status code'); - $this->assertContains('Hello, full', $resp->getBody()->getContents()); + $this->assertStringContainsString('Hello, full', $resp->getBody()->getContents()); $this->runEventuallyConsistentTest(function () { $this->assertBreakpointCount(0); @@ -141,7 +143,7 @@ public function testWithExtraPath() $resp = $this->httpClient->get('hello/extra'); $this->assertEquals('200', $resp->getStatusCode(), 'hello/extra status code'); - $this->assertContains('Hello, extra', $resp->getBody()->getContents()); + $this->assertStringContainsString('Hello, extra', $resp->getBody()->getContents()); $this->runEventuallyConsistentTest(function () { $this->assertBreakpointCount(0); @@ -158,7 +160,7 @@ public function testWithMissingPath() $resp = $this->httpClient->get('hello/missing'); $this->assertEquals('200', $resp->getStatusCode(), 'hello/missing status code'); - $this->assertContains('Hello, missing', $resp->getBody()->getContents()); + $this->assertStringContainsString('Hello, missing', $resp->getBody()->getContents()); $this->runEventuallyConsistentTest(function () { $this->assertBreakpointCount(0); diff --git a/Debugger/tests/Unit/AgentTest.php b/Debugger/tests/Unit/AgentTest.php index 0ae5cc4d508f..89d56a23c78f 100644 --- a/Debugger/tests/Unit/AgentTest.php +++ b/Debugger/tests/Unit/AgentTest.php @@ -26,7 +26,7 @@ use Google\Cloud\Debugger\BreakpointStorage\BreakpointStorageInterface; use Psr\Log\LoggerInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -37,9 +37,8 @@ class AgentTest extends TestCase private $storage; private $oldDaemonEnv; - public function setUp() + public function set_up() { - parent::setUp(); $this->oldDaemonEnv = getenv('IS_BATCH_DAEMON_RUNNING'); if (PHP_MAJOR_VERSION < 7) { @@ -54,14 +53,13 @@ public function setUp() $this->logger = $this->prophesize(LoggerInterface::class); } - public function tearDown() + public function tear_down() { if ($this->oldDaemonEnv === false) { putenv('IS_BATCH_DAEMON_RUNNING'); } else { putenv('IS_BATCH_DAEMON_RUNNING=' . $this->oldDaemonEnv); } - parent::tearDown(); } public function testSpecifyStorage() diff --git a/Debugger/tests/Unit/BreakpointStorage/FileBreakpointStorageTest.php b/Debugger/tests/Unit/BreakpointStorage/FileBreakpointStorageTest.php index 6744fb53e119..794cc1348468 100644 --- a/Debugger/tests/Unit/BreakpointStorage/FileBreakpointStorageTest.php +++ b/Debugger/tests/Unit/BreakpointStorage/FileBreakpointStorageTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Debugger\Breakpoint; use Google\Cloud\Debugger\Connection\ConnectionInterface; use Google\Cloud\Debugger\Debuggee; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -30,7 +30,7 @@ class FileBreakpointStorageTest extends TestCase { private $storage; - public function setUp() + public function set_up() { $this->storage = new FileBreakpointStorage(); } diff --git a/Debugger/tests/Unit/BreakpointStorage/SysvBreakpointStorageTest.php b/Debugger/tests/Unit/BreakpointStorage/SysvBreakpointStorageTest.php index c92730f47ff3..00d83c69431f 100644 --- a/Debugger/tests/Unit/BreakpointStorage/SysvBreakpointStorageTest.php +++ b/Debugger/tests/Unit/BreakpointStorage/SysvBreakpointStorageTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Debugger\Connection\ConnectionInterface; use Google\Cloud\Debugger\Debuggee; use Google\Cloud\Core\SysvTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -33,7 +33,7 @@ class SysvBreakpointStorageTest extends TestCase private $storage; - public function setUp() + public function set_up() { if (!$this->isSysvIPCLoaded()) { $this->markTestSkipped( diff --git a/Debugger/tests/Unit/BreakpointValidationTest.php b/Debugger/tests/Unit/BreakpointValidationTest.php index abb4b3a22337..e489a90f8221 100644 --- a/Debugger/tests/Unit/BreakpointValidationTest.php +++ b/Debugger/tests/Unit/BreakpointValidationTest.php @@ -20,14 +20,14 @@ use Google\Cloud\Debugger\StatusMessage; use Google\Cloud\Debugger\Breakpoint; use Google\Cloud\Debugger\SourceLocation; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger */ class BreakpointValidationTest extends TestCase { - public function setUp() + public function set_up() { if (!extension_loaded('stackdriver_debugger')) { $this->markTestSkipped('Breakpoint validation requires stackdriver_debugger extension'); diff --git a/Debugger/tests/Unit/CliDaemonTest.php b/Debugger/tests/Unit/CliDaemonTest.php index 35b46a897065..d4e0ddb9816f 100644 --- a/Debugger/tests/Unit/CliDaemonTest.php +++ b/Debugger/tests/Unit/CliDaemonTest.php @@ -19,12 +19,15 @@ use Google\Cloud\Debugger\CliDaemon; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group debugger */ class CliDaemonTest extends TestCase { + use ExpectException; + public function testClientConfig() { new CliDaemon([ @@ -32,21 +35,19 @@ public function testClientConfig() ]); } - /** - * @expectedException UnexpectedValueException - */ public function testClientConfigMissing() { + $this->expectException('UnexpectedValueException'); + new CliDaemon([ 'config' => 'non-existent-file' ]); } - /** - * @expectedException UnexpectedValueException - */ public function testClientConfigWrongReturn() { + $this->expectException('UnexpectedValueException'); + new CliDaemon([ 'config' => implode(DIRECTORY_SEPARATOR, [dirname(__FILE__), 'data', 'daemon_config_wrong_return.php']) ]); @@ -59,31 +60,28 @@ public function testSourceRoot() ]); } - /** - * @expectedException UnexpectedValueException - */ public function testSourceRootMissing() { + $this->expectException('UnexpectedValueException'); + new CliDaemon([ 'sourceRoot' => 'non-existent-directory' ]); } - /** - * @expectedException UnexpectedValueException - */ public function testSourceRootInvalid() { + $this->expectException('UnexpectedValueException'); + new CliDaemon([ 'sourceRoot' => __FILE__ ]); } - /** - * @expectedException InvalidArgumentException - */ public function testDefaults() { + $this->expectException('InvalidArgumentException'); + new CliDaemon(); } } diff --git a/Debugger/tests/Unit/Connection/GrpcTest.php b/Debugger/tests/Unit/Connection/GrpcTest.php index 15ef5de42311..b4861e261c59 100644 --- a/Debugger/tests/Unit/Connection/GrpcTest.php +++ b/Debugger/tests/Unit/Connection/GrpcTest.php @@ -25,7 +25,7 @@ use Google\Cloud\Debugger\V2\Breakpoint; use Google\Cloud\Debugger\V2\Debuggee; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -37,7 +37,7 @@ class GrpcTest extends TestCase private $requestWrapper; private $successMessage; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Debugger/tests/Unit/Connection/RestTest.php b/Debugger/tests/Unit/Connection/RestTest.php index 0fac2ea93c98..6b65da038756 100644 --- a/Debugger/tests/Unit/Connection/RestTest.php +++ b/Debugger/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Debugger\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Debugger/tests/Unit/DaemonTest.php b/Debugger/tests/Unit/DaemonTest.php index db283789b526..a866a28f3af9 100644 --- a/Debugger/tests/Unit/DaemonTest.php +++ b/Debugger/tests/Unit/DaemonTest.php @@ -24,7 +24,7 @@ use Google\Cloud\Debugger\Debuggee; use Google\Cloud\Debugger\DebuggerClient; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -35,7 +35,7 @@ class DaemonTest extends TestCase private $debuggee; private $storage; - public function setUp() + public function set_up() { $this->client = $this->prophesize(DebuggerClient::class); $this->debuggee = $this->prophesize(Debuggee::class); diff --git a/Debugger/tests/Unit/DebuggeeTest.php b/Debugger/tests/Unit/DebuggeeTest.php index 4e97eb8b4e9c..2708b8385c40 100644 --- a/Debugger/tests/Unit/DebuggeeTest.php +++ b/Debugger/tests/Unit/DebuggeeTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Debugger\ExtendedSourceContext; use Google\Cloud\Debugger\Connection\ConnectionInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -32,7 +32,7 @@ class DebuggeeTest extends TestCase { private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/Debugger/tests/Unit/DebuggerClientTest.php b/Debugger/tests/Unit/DebuggerClientTest.php index ea4a46074d8b..6b2a6b2b27be 100644 --- a/Debugger/tests/Unit/DebuggerClientTest.php +++ b/Debugger/tests/Unit/DebuggerClientTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Debugger\Connection\ConnectionInterface; use Google\Cloud\Debugger\Debuggee; use Google\Cloud\Debugger\DebuggerClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -34,7 +34,7 @@ class DebuggerClientTest extends TestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(DebuggerClient::class, [ ['projectId' => self::PROJECT] diff --git a/Debugger/tests/Unit/SourceLocationResolverTest.php b/Debugger/tests/Unit/SourceLocationResolverTest.php index 575fb70ab6b7..051fbbe29a2c 100644 --- a/Debugger/tests/Unit/SourceLocationResolverTest.php +++ b/Debugger/tests/Unit/SourceLocationResolverTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Debugger\SourceLocation; use Google\Cloud\Debugger\SourceLocationResolver; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group debugger @@ -28,7 +28,7 @@ class SourceLocationResolverTest extends TestCase { private static $cwd; - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$cwd = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '../../'])); } diff --git a/Debugger/tests/Unit/VariableTableTest.php b/Debugger/tests/Unit/VariableTableTest.php index 69014f19aa95..79157e2ff781 100644 --- a/Debugger/tests/Unit/VariableTableTest.php +++ b/Debugger/tests/Unit/VariableTableTest.php @@ -21,12 +21,17 @@ use Google\Cloud\Debugger\VariableTable; use Google\Cloud\Core\Int64; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group debugger */ class VariableTableTest extends TestCase { + use AssertIsType; + use AssertionRenames; + public function testRegisterObjectCreatesVariable() { $variableTable = new VariableTable(); @@ -49,7 +54,10 @@ public function testRegisterObjectCreatesVariable() $this->assertEquals('int', $variableData['name']); $this->assertArrayNotHasKey('varTableIndex', $variableData); $this->assertEquals(Int64::class, $variableData['type']); - $this->assertRegexp('/Google\\\\Cloud\\\\Core\\\\Int64 \([0-9a-z]+\)/', $variableData['value']); + $this->assertMatchesRegularExpression( + '/Google\\\\Cloud\\\\Core\\\\Int64 \([0-9a-z]+\)/', + $variableData['value'] + ); $this->assertArrayNotHasKey('status', $variableData); } @@ -179,7 +187,7 @@ public function testRegistersArrayMembers() $data = $variable->info(); $this->assertCount(3, $data['members']); foreach ($data['members'] as $member) { - $this->assertInternalType('string', $member['name']); + $this->assertIsString($member['name']); } } diff --git a/Deploy/composer.json b/Deploy/composer.json index 019e72d2ff2e..177356460ab3 100644 --- a/Deploy/composer.json +++ b/Deploy/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Dialogflow/composer.json b/Dialogflow/composer.json index 69022bc4011a..c268a01ab991 100644 --- a/Dialogflow/composer.json +++ b/Dialogflow/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Dlp/composer.json b/Dlp/composer.json index 529fae4f2de5..e63140b0487a 100644 --- a/Dlp/composer.json +++ b/Dlp/composer.json @@ -7,7 +7,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Dms/composer.json b/Dms/composer.json index e055f4cd2e40..b4b412a65436 100644 --- a/Dms/composer.json +++ b/Dms/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/DocumentAi/composer.json b/DocumentAi/composer.json index 137fd03eb5c3..15e8bccc6acb 100644 --- a/DocumentAi/composer.json +++ b/DocumentAi/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Domains/composer.json b/Domains/composer.json index 7326b34ae8ec..4fda786bcb7d 100644 --- a/Domains/composer.json +++ b/Domains/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ErrorReporting/composer.json b/ErrorReporting/composer.json index f3b9424a9355..cd85370e7866 100644 --- a/ErrorReporting/composer.json +++ b/ErrorReporting/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/ErrorReporting/tests/Unit/BootstrapTest.php b/ErrorReporting/tests/Unit/BootstrapTest.php index e9eb34cd223a..2e9ef77af48f 100644 --- a/ErrorReporting/tests/Unit/BootstrapTest.php +++ b/ErrorReporting/tests/Unit/BootstrapTest.php @@ -22,7 +22,7 @@ use Google\Cloud\ErrorReporting\MockValues; use Google\Cloud\Logging\PsrLogger; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; //@codingStandardsIgnoreStart require_once __DIR__ . '/fakeGlobalFunctions.php'; @@ -37,7 +37,7 @@ class BootstrapTest extends TestCase private $psrBatchLogger; private $metadataProvider; - public function setUp() + public function set_up() { $this->psrBatchLogger = $this->prophesize(PsrLogger::class); } diff --git a/EssentialContacts/composer.json b/EssentialContacts/composer.json index 87495609a0f4..3d048f0d5310 100644 --- a/EssentialContacts/composer.json +++ b/EssentialContacts/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Eventarc/composer.json b/Eventarc/composer.json index 1beeda962e79..6b65fca961ea 100644 --- a/Eventarc/composer.json +++ b/Eventarc/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/EventarcPublishing/composer.json b/EventarcPublishing/composer.json index 1d3be2fbd37e..e13eb037b4ce 100644 --- a/EventarcPublishing/composer.json +++ b/EventarcPublishing/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Filestore/composer.json b/Filestore/composer.json index c016bc287e54..7521498cdb8e 100644 --- a/Filestore/composer.json +++ b/Filestore/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Firestore/composer.json b/Firestore/composer.json index 85e1caa347d8..f6d736afe8c2 100644 --- a/Firestore/composer.json +++ b/Firestore/composer.json @@ -10,7 +10,8 @@ "ramsey/uuid": "^3.0|^4.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6" diff --git a/Firestore/phpunit-snippets.xml.dist b/Firestore/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Firestore/phpunit-snippets.xml.dist +++ b/Firestore/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Firestore/tests/Snippet/CollectionReferenceTest.php b/Firestore/tests/Snippet/CollectionReferenceTest.php index c8d136c82eaf..7f30b073624e 100644 --- a/Firestore/tests/Snippet/CollectionReferenceTest.php +++ b/Firestore/tests/Snippet/CollectionReferenceTest.php @@ -42,7 +42,7 @@ class CollectionReferenceTest extends SnippetTestCase private $connection; private $collection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->collection = TestHelpers::stub(CollectionReference::class, [ diff --git a/Firestore/tests/Snippet/DocumentReferenceTest.php b/Firestore/tests/Snippet/DocumentReferenceTest.php index 9dff5f2fadd4..7877d8924384 100644 --- a/Firestore/tests/Snippet/DocumentReferenceTest.php +++ b/Firestore/tests/Snippet/DocumentReferenceTest.php @@ -43,7 +43,7 @@ class DocumentReferenceTest extends SnippetTestCase private $document; private $batch; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->document = TestHelpers::stub(DocumentReferenceStub::class, [ diff --git a/Firestore/tests/Snippet/DocumentSnapshotTest.php b/Firestore/tests/Snippet/DocumentSnapshotTest.php index cbfb066897b3..ffb22d4f5551 100644 --- a/Firestore/tests/Snippet/DocumentSnapshotTest.php +++ b/Firestore/tests/Snippet/DocumentSnapshotTest.php @@ -40,7 +40,7 @@ class DocumentSnapshotTest extends SnippetTestCase private $snapshot; - public function setUp() + public function set_up() { $ref = $this->prophesize(DocumentReference::class); $ref->name()->willReturn(self::DOCUMENT); diff --git a/Firestore/tests/Snippet/FieldPathTest.php b/Firestore/tests/Snippet/FieldPathTest.php index 749a20148263..5aca3a7574b3 100644 --- a/Firestore/tests/Snippet/FieldPathTest.php +++ b/Firestore/tests/Snippet/FieldPathTest.php @@ -31,7 +31,7 @@ class FieldPathTest extends SnippetTestCase private $fieldPath; - public function setUp() + public function set_up() { $this->fieldPath = new FieldPath([]); } diff --git a/Firestore/tests/Snippet/FieldValueTest.php b/Firestore/tests/Snippet/FieldValueTest.php index ace8b678699b..58a20e33bc16 100644 --- a/Firestore/tests/Snippet/FieldValueTest.php +++ b/Firestore/tests/Snippet/FieldValueTest.php @@ -36,7 +36,7 @@ class FieldValueTest extends SnippetTestCase private $connection; private $firestore; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Firestore/tests/Snippet/FirestoreClientTest.php b/Firestore/tests/Snippet/FirestoreClientTest.php index ac3899fe0a5a..f93e6eea40f5 100644 --- a/Firestore/tests/Snippet/FirestoreClientTest.php +++ b/Firestore/tests/Snippet/FirestoreClientTest.php @@ -47,7 +47,7 @@ class FirestoreClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php b/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php index c4049392e3e1..16758d91d79e 100644 --- a/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php +++ b/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php @@ -24,6 +24,7 @@ use Google\Cloud\Firestore\FirestoreClient; use Google\Cloud\Firestore\FirestoreSessionHandler; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -32,6 +33,7 @@ */ class FirestoreSessionHandlerTest extends SnippetTestCase { + use ExpectException; use GrpcTestTrait; const TRANSACTION = 'transaction-id'; @@ -39,9 +41,9 @@ class FirestoreSessionHandlerTest extends SnippetTestCase private $connection; private $client; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); // Since the tests in this class must run in isolation, they won't be // recognized as having been covered, and will cause a CI error. @@ -52,7 +54,7 @@ public static function setUpBeforeClass() self::snippetFromMethod(FirestoreClient::class, 'sessionHandler'); } - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -145,11 +147,10 @@ public function testSessionHandlerMethod() $this->assertEquals('Bob', $res->output()); } - /** - * @expectedException \RuntimeException - */ public function testClassErrorHandler() { + $this->expectException('\RuntimeException'); + $snippet = $this->snippetFromClass(FirestoreSessionHandler::class, 1); $snippet->replace('$firestore = new FirestoreClient();', ''); diff --git a/Firestore/tests/Snippet/QuerySnapshotTest.php b/Firestore/tests/Snippet/QuerySnapshotTest.php index c5624403cb90..5fed133ba505 100644 --- a/Firestore/tests/Snippet/QuerySnapshotTest.php +++ b/Firestore/tests/Snippet/QuerySnapshotTest.php @@ -37,7 +37,7 @@ class QuerySnapshotTest extends SnippetTestCase private $connection; private $snapshot; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->snapshot = TestHelpers::stub(QuerySnapshot::class, [ diff --git a/Firestore/tests/Snippet/QueryTest.php b/Firestore/tests/Snippet/QueryTest.php index 3003a63d5666..d5fb40129e8a 100644 --- a/Firestore/tests/Snippet/QueryTest.php +++ b/Firestore/tests/Snippet/QueryTest.php @@ -43,7 +43,7 @@ class QueryTest extends SnippetTestCase private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/Firestore/tests/Snippet/TransactionTest.php b/Firestore/tests/Snippet/TransactionTest.php index 25892c84886f..4d77264b472c 100644 --- a/Firestore/tests/Snippet/TransactionTest.php +++ b/Firestore/tests/Snippet/TransactionTest.php @@ -53,7 +53,7 @@ class TransactionTest extends SnippetTestCase private $document; private $batch; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->transaction = TestHelpers::stub(TransactionStub::class, [ diff --git a/Firestore/tests/Snippet/WriteBatchTest.php b/Firestore/tests/Snippet/WriteBatchTest.php index d8d0666cbd12..498efe6dff44 100644 --- a/Firestore/tests/Snippet/WriteBatchTest.php +++ b/Firestore/tests/Snippet/WriteBatchTest.php @@ -41,7 +41,7 @@ class WriteBatchTest extends SnippetTestCase private $connection; private $batch; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->batch = TestHelpers::stub(WriteBatch::class, [ diff --git a/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php b/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php index 00b61f563510..264ca149c7c4 100644 --- a/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php +++ b/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php @@ -36,7 +36,7 @@ class FirestoreAdminClientSmokeTest extends SystemTestCase private static $projectId; private static $hasSetup = false; - public static function setupBeforeClass() + public static function set_up_before_class() { if (self::$hasSetup) { return; diff --git a/Firestore/tests/System/DocumentAndCollectionTest.php b/Firestore/tests/System/DocumentAndCollectionTest.php index 85ec781f88c7..96154e0ed3d7 100644 --- a/Firestore/tests/System/DocumentAndCollectionTest.php +++ b/Firestore/tests/System/DocumentAndCollectionTest.php @@ -28,7 +28,7 @@ class DocumentAndCollectionTest extends FirestoreTestCase { private $document; - public function setUp() + public function set_up() { $this->document = self::$collection->add([ 'firstName' => 'John', diff --git a/Firestore/tests/System/FieldValueTest.php b/Firestore/tests/System/FieldValueTest.php index f6ca786f4257..e465a673c826 100644 --- a/Firestore/tests/System/FieldValueTest.php +++ b/Firestore/tests/System/FieldValueTest.php @@ -28,7 +28,7 @@ class FieldValueTest extends FirestoreTestCase { private $document; - public function setUp() + public function set_up() { $this->document = self::$collection->add([ 'firstName' => 'John', diff --git a/Firestore/tests/System/FirestoreTestCase.php b/Firestore/tests/System/FirestoreTestCase.php index bb5f6ecb2d9f..46d378e580bf 100644 --- a/Firestore/tests/System/FirestoreTestCase.php +++ b/Firestore/tests/System/FirestoreTestCase.php @@ -31,7 +31,7 @@ class FirestoreTestCase extends SystemTestCase protected static $localDeletionQueue; private static $hasSetUp = false; - public static function setupBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Firestore/tests/System/GetAllDocumentsTest.php b/Firestore/tests/System/GetAllDocumentsTest.php index a18fc948eb2a..8dccb0929c02 100644 --- a/Firestore/tests/System/GetAllDocumentsTest.php +++ b/Firestore/tests/System/GetAllDocumentsTest.php @@ -30,9 +30,9 @@ class GetAllDocumentsTest extends FirestoreTestCase private static $refsExist = []; private static $refsNonExist = []; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); $c = self::$client->collection(uniqid(self::COLLECTION_NAME)); self::$localDeletionQueue->add($c); diff --git a/Firestore/tests/System/QueryTest.php b/Firestore/tests/System/QueryTest.php index a50c3d703842..60a2e3083470 100644 --- a/Firestore/tests/System/QueryTest.php +++ b/Firestore/tests/System/QueryTest.php @@ -27,7 +27,7 @@ class QueryTest extends FirestoreTestCase { private $query; - public function setUp() + public function set_up() { $this->query = self::$client->collection(uniqid(self::COLLECTION_NAME)); self::$localDeletionQueue->add($this->query); diff --git a/Firestore/tests/System/TransactionTest.php b/Firestore/tests/System/TransactionTest.php index 6745f1efc765..0cbae19f8b8c 100644 --- a/Firestore/tests/System/TransactionTest.php +++ b/Firestore/tests/System/TransactionTest.php @@ -25,7 +25,7 @@ class TransactionTest extends FirestoreTestCase { private $document; - public function setUp() + public function set_up() { $doc = self::$collection->newDocument(); $this->document = $doc; diff --git a/Firestore/tests/System/ValueMapperTest.php b/Firestore/tests/System/ValueMapperTest.php index 22dcad309c1d..eb48d931f341 100644 --- a/Firestore/tests/System/ValueMapperTest.php +++ b/Firestore/tests/System/ValueMapperTest.php @@ -32,9 +32,9 @@ class ValueMapperTest extends FirestoreTestCase const FIELD = 'testedField'; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); if (!self::$isSetup) { self::$document = self::$collection->add([]); @@ -63,7 +63,7 @@ public function testValue($input, callable $expectation = null) public function values() { - self::setupBeforeClass(); + self::set_up_before_class(); return [ [null], diff --git a/Firestore/tests/Unit/CollectionReferenceTest.php b/Firestore/tests/Unit/CollectionReferenceTest.php index 7c91ffe0cba2..3b9b3563b306 100644 --- a/Firestore/tests/Unit/CollectionReferenceTest.php +++ b/Firestore/tests/Unit/CollectionReferenceTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Firestore\Tests\Unit; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Google\Cloud\Firestore\Query; use Google\Cloud\Firestore\ValueMapper; use Google\Cloud\Core\Testing\TestHelpers; @@ -41,7 +41,7 @@ class CollectionReferenceTest extends TestCase private $connection; private $collection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->collection = TestHelpers::stub(CollectionReference::class, [ diff --git a/Firestore/tests/Unit/ConformanceTest.php b/Firestore/tests/Unit/ConformanceTest.php index 3e1a9b45933f..50e1b8d9d73f 100644 --- a/Firestore/tests/Unit/ConformanceTest.php +++ b/Firestore/tests/Unit/ConformanceTest.php @@ -36,7 +36,7 @@ use Google\Cloud\Firestore\V1\StructuredQuery\FieldFilter\Operator as FieldFilterOperator; use Google\Cloud\Firestore\V1\StructuredQuery\UnaryFilter\Operator as UnaryFilterOperator; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Prophecy\Exception\Call\UnexpectedCallException; @@ -75,7 +75,7 @@ class ConformanceTest extends TestCase 'set-merge: One merge path cannot be the prefix of another', ]; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Firestore/tests/Unit/Connection/GrpcTest.php b/Firestore/tests/Unit/Connection/GrpcTest.php index 7e7696d1a019..36c70ba24e57 100644 --- a/Firestore/tests/Unit/Connection/GrpcTest.php +++ b/Firestore/tests/Unit/Connection/GrpcTest.php @@ -31,7 +31,7 @@ use Google\Cloud\Firestore\V1\TransactionOptions_ReadWrite; use Google\Cloud\Firestore\V1\Value; use Google\Cloud\Firestore\V1\Write; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -48,7 +48,7 @@ class GrpcTest extends TestCase private $successMessage; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Firestore/tests/Unit/DocumentReferenceTest.php b/Firestore/tests/Unit/DocumentReferenceTest.php index 3dcd099d55cf..7b42885c6b27 100644 --- a/Firestore/tests/Unit/DocumentReferenceTest.php +++ b/Firestore/tests/Unit/DocumentReferenceTest.php @@ -26,7 +26,8 @@ use Google\Cloud\Firestore\DocumentSnapshot; use Google\Cloud\Firestore\FieldPath; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations; use Prophecy\Argument; /** @@ -35,6 +36,7 @@ */ class DocumentReferenceTest extends TestCase { + use AssertEqualsSpecializations; use TimeTrait; const PROJECT = 'example_project'; @@ -45,7 +47,7 @@ class DocumentReferenceTest extends TestCase private $connection; private $document; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); @@ -274,6 +276,6 @@ public function testWriteResult() $res = $this->document->set(['foo' => 'bar']); $this->assertInstanceOf(Timestamp::class, $res['updateTime']); - $this->assertEquals($time + 100, $res['updateTime']->get()->format('U'), '', 3); + $this->assertEqualsWithDelta($time + 100, $res['updateTime']->get()->format('U'), 3); } } diff --git a/Firestore/tests/Unit/DocumentSnapshotTest.php b/Firestore/tests/Unit/DocumentSnapshotTest.php index 31882b1648ec..27e8f837cab6 100644 --- a/Firestore/tests/Unit/DocumentSnapshotTest.php +++ b/Firestore/tests/Unit/DocumentSnapshotTest.php @@ -24,7 +24,9 @@ use Google\Cloud\Firestore\DocumentSnapshot; use Google\Cloud\Firestore\FieldPath; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; /** * @group firestore @@ -32,12 +34,15 @@ */ class DocumentSnapshotTest extends TestCase { + use ExpectException; + use ExpectPHPException; + const NAME = 'projects/example_project/databases/(default)/documents/a/b'; const ID = 'b'; private $snapshot; - public function setUp() + public function set_up() { $ref = $this->prophesize(DocumentReference::class); $ref->name()->willReturn(self::NAME); @@ -166,19 +171,17 @@ public function testGetWithFieldPath() $this->assertNull($this->snapshot->get(new FieldPath(['null']))); } - /** - * @expectedException InvalidArgumentException - */ public function testGetInvalid() { + $this->expectException('InvalidArgumentException'); + $this->snapshot->get('foo'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetInvalidArgumentType() { + $this->expectException('InvalidArgumentException'); + $this->snapshot->get(1234); } @@ -190,27 +193,24 @@ public function testArrayAccessRead() $this->assertArrayNotHasKey('baz', $this->snapshot); } - /** - * @expectedException BadMethodCallException - */ public function testArrayAccessSetDisabled() { + $this->expectException('BadMethodCallException'); + $this->snapshot['name'] = 'bob'; } - /** - * @expectedException BadMethodCallException - */ public function testArrayAccessUnsetDisabled() { + $this->expectException('BadMethodCallException'); + unset($this->snapshot['name']); } - /** - * @expectedException PHPUnit_Framework_Error_Notice - */ public function testArrayAccessNonExistentIndex() { + $this->expectError(); + $this->snapshot['name']; } } diff --git a/Firestore/tests/Unit/FieldPathTest.php b/Firestore/tests/Unit/FieldPathTest.php index 7fcd857f29bc..b09a3c6406b1 100644 --- a/Firestore/tests/Unit/FieldPathTest.php +++ b/Firestore/tests/Unit/FieldPathTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Firestore\FieldPath; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -26,6 +27,8 @@ */ class FieldPathTest extends TestCase { + use ExpectException; + private $pieces = ['foo', 'bar', 'hello', 'world']; public function testConstruct() @@ -34,11 +37,10 @@ public function testConstruct() $this->assertEquals($this->pieces, $fieldPath->path()); } - /** - * @expectedException InvalidArgumentException - */ public function testEmptyElements() { + $this->expectException('InvalidArgumentException'); + new FieldPath(['']); } @@ -56,10 +58,11 @@ public function testFromString() /** * @dataProvider invalidPaths - * @expectedException InvalidArgumentException */ public function testInvalidPaths($path) { + $this->expectException('InvalidArgumentException'); + FieldPath::fromString($path); } diff --git a/Firestore/tests/Unit/FirestoreClientTest.php b/Firestore/tests/Unit/FirestoreClientTest.php index b2213e6cd569..4bdb149dcb67 100644 --- a/Firestore/tests/Unit/FirestoreClientTest.php +++ b/Firestore/tests/Unit/FirestoreClientTest.php @@ -32,8 +32,9 @@ use Google\Cloud\Firestore\FirestoreSessionHandler; use Google\Cloud\Firestore\Query; use Google\Cloud\Firestore\WriteBatch; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -41,6 +42,7 @@ */ class FirestoreClientTest extends TestCase { + use ExpectException; use GrpcTestTrait; const PROJECT = 'example_project'; @@ -49,7 +51,7 @@ class FirestoreClientTest extends TestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -175,10 +177,11 @@ public function testDocumentPathSpecialChars() /** * @dataProvider paths - * @expectedException InvalidArgumentException */ public function testInvalidPath($method, $name) { + $this->expectException('InvalidArgumentException'); + call_user_func([$this->client, $method], $name); } @@ -228,11 +231,10 @@ public function testDocuments(array $input, array $names) $this->assertEquals('world', $res[0]['hello']); } - /** - * @expectedException InvalidArgumentException - */ public function testDocumentsInvalidInputType() { + $this->expectException('InvalidArgumentException'); + $this->client->documents([ 10 ]); @@ -352,11 +354,10 @@ public function testCollectionGroup() $query->documents(); } - /** - * @expectedException InvalidArgumentException - */ public function testCollectionGroupInvalidId() { + $this->expectException('InvalidArgumentException'); + $this->client->collectionGroup('foo/bar'); } @@ -430,12 +431,11 @@ public function testRunTransactionRetryable() $this->assertEquals('foo', $res); } - /** - * @expectedException RangeException - * @expectedExceptionMessage foo - */ public function testRunTransactionNotRetryable() { + $this->expectException('RangeException'); + $this->expectExceptionMessage('foo'); + $transactionId = 'foobar'; $timestamp = new Timestamp(new \DateTimeImmutable); @@ -459,11 +459,10 @@ public function testRunTransactionNotRetryable() }); } - /** - * @expectedException Google\Cloud\Core\Exception\AbortedException - */ public function testRunTransactionExceedsMaxRetries() { + $this->expectException('Google\Cloud\Core\Exception\AbortedException'); + $transactionId = 'foobar'; $timestamp = new Timestamp(new \DateTimeImmutable); @@ -486,11 +485,10 @@ public function testRunTransactionExceedsMaxRetries() }); } - /** - * @expectedException Google\Cloud\Core\Exception\AbortedException - */ public function testRunTransactionExceedsMaxRetriesLowerLimit() { + $this->expectException('Google\Cloud\Core\Exception\AbortedException'); + $transactionId = 'foobar'; $timestamp = new Timestamp(new \DateTimeImmutable); diff --git a/Firestore/tests/Unit/FirestoreSessionHandlerTest.php b/Firestore/tests/Unit/FirestoreSessionHandlerTest.php index 2f169bebf015..fb3201a5c876 100644 --- a/Firestore/tests/Unit/FirestoreSessionHandlerTest.php +++ b/Firestore/tests/Unit/FirestoreSessionHandlerTest.php @@ -27,9 +27,11 @@ use Google\Cloud\Firestore\FirestoreSessionHandler; use Google\Cloud\Firestore\Transaction; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Iterator; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; /** * @group firestore @@ -37,6 +39,9 @@ */ class FirestoreSessionHandlerTest extends TestCase { + use ExpectException; + use ExpectPHPException; + const SESSION_SAVE_PATH = 'sessions'; const SESSION_NAME = 'PHPSESSID'; const PROJECT = 'example_project'; @@ -46,7 +51,7 @@ class FirestoreSessionHandlerTest extends TestCase private $valueMapper; private $documents; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->valueMapper = $this->prophesize(ValueMapper::class); @@ -68,11 +73,10 @@ public function testOpen() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testOpenWithException() { + $this->expectWarning(); + $this->connection->beginTransaction(['database' => $this->dbName()]) ->shouldBeCalledTimes(1) ->willThrow(new ServiceException('')); @@ -86,11 +90,10 @@ public function testOpenWithException() $this->assertFalse($ret); } - /** - * @expectedException InvalidArgumentException - */ public function testReadNotAllowed() { + $this->expectException('InvalidArgumentException'); + $this->connection->beginTransaction(['database' => $this->dbName()]) ->shouldBeCalledTimes(1) ->willReturn(['transaction' => null]); @@ -149,11 +152,10 @@ public function testReadNothing() $this->assertEquals('', $ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testReadWithException() { + $this->expectWarning(); + $this->connection->beginTransaction(['database' => $this->dbName()]) ->shouldBeCalledTimes(1) ->willReturn(['transaction' => null]); @@ -253,11 +255,10 @@ public function testWrite() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testWriteWithException() { + $this->expectWarning(); + $phpunit = $this; $this->valueMapper->encodeValues(Argument::type('array')) ->will(function ($args) use ($phpunit) { @@ -318,11 +319,10 @@ public function testDestroy() $this->assertTrue($ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testDestroyWithException() { + $this->expectWarning(); + $this->connection->beginTransaction(['database' => $this->dbName()]) ->shouldBeCalledTimes(1) ->willReturn(['transaction' => 123]); @@ -432,11 +432,10 @@ public function testGc() $this->assertEquals(1, $ret); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testGcWithException() { + $this->expectWarning(); + $this->connection->beginTransaction(['database' => $this->dbName()]) ->shouldBeCalledTimes(2) ->willReturn(['transaction' => 123]); diff --git a/Firestore/tests/Unit/PathTraitTest.php b/Firestore/tests/Unit/PathTraitTest.php index 66cd0a92ee22..41071117936a 100644 --- a/Firestore/tests/Unit/PathTraitTest.php +++ b/Firestore/tests/Unit/PathTraitTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Firestore\PathTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group firestore @@ -35,7 +35,7 @@ class PathTraitTest extends TestCase private $impl; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(PathTrait::class); } diff --git a/Firestore/tests/Unit/QuerySnapshotTest.php b/Firestore/tests/Unit/QuerySnapshotTest.php index 1a90af765f07..4adbdd6334d2 100644 --- a/Firestore/tests/Unit/QuerySnapshotTest.php +++ b/Firestore/tests/Unit/QuerySnapshotTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Firestore\Connection\ConnectionInterface; use Google\Cloud\Firestore\Query; use Google\Cloud\Firestore\QuerySnapshot; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group firestore @@ -32,7 +32,7 @@ class QuerySnapshotTest extends TestCase private $connection; private $snapshot; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->snapshot = TestHelpers::stub(QuerySnapshot::class, [ diff --git a/Firestore/tests/Unit/QueryTest.php b/Firestore/tests/Unit/QueryTest.php index 206015077f1c..768ed21a8257 100644 --- a/Firestore/tests/Unit/QueryTest.php +++ b/Firestore/tests/Unit/QueryTest.php @@ -32,8 +32,9 @@ use Google\Cloud\Firestore\V1\StructuredQuery\Direction; use Google\Cloud\Firestore\V1\StructuredQuery\FieldFilter\Operator as FieldFilterOperator; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -41,6 +42,8 @@ */ class QueryTest extends TestCase { + use ExpectException; + const PROJECT = 'example_project'; const DATABASE = '(default)'; const QUERY_PARENT = 'projects/example_project/databases/(default)/documents'; @@ -55,7 +58,7 @@ class QueryTest extends TestCase private $query; private $collectionGroupQuery; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->query = TestHelpers::stub(Query::class, [ @@ -75,11 +78,10 @@ public function setUp() ], ['connection', 'query', 'transaction']); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructMissingFrom() { + $this->expectException('InvalidArgumentException'); + new Query( $this->connection->reveal(), new ValueMapper($this->connection->reveal(), false), @@ -278,10 +280,11 @@ public function testWhere() /** * @dataProvider invalidUnaryComparisonOperators - * @expectedException InvalidArgumentException */ public function testWhereUnaryInvalidComparisonOperator($operator) { + $this->expectException('InvalidArgumentException'); + $this->query->where('foo', $operator, null); } @@ -331,19 +334,19 @@ public function whereOperators() } /** - * @expectedException InvalidArgumentException * @dataProvider sentinels */ public function testWhereInvalidSentinelValue($sentinel) { + $this->expectException('InvalidArgumentException'); + $this->query->where('foo', '=', $sentinel); } - /** - * @expectedException InvalidArgumentException - */ public function testWhereInvalidOperator() { + $this->expectException('InvalidArgumentException'); + $this->query->where('foo', 'hello', 'bar'); } @@ -430,10 +433,11 @@ public function whereDocument() /** * @dataProvider whereInvalidDocument - * @expectedException InvalidArgumentException */ public function testWhereInvalidDocument($document) { + $this->expectException('InvalidArgumentException'); + $this->query->where(FieldPath::documentId(), '=', $document); } @@ -472,11 +476,12 @@ public function testOrderBy() } /** - * @expectedException InvalidArgumentException * @dataProvider cursors */ public function testOrderByAfterCursor($cursor) { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy('foo')->$cursor(['bar'])->orderBy('world'); } @@ -511,11 +516,10 @@ public function orderOperators() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testOrderByInvalidOperator() { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy('foo', 'hello'); } @@ -714,11 +718,10 @@ public function testLimitToLastReversesResults() $this->assertEquals($name1, $rows[1]->name()); } - /** - * @expectedException \RuntimeException - */ public function testLimitToLastWithoutOrderBy() { + $this->expectException('\RuntimeException'); + $this->query->limitToLast(1)->documents()->current(); } @@ -949,20 +952,18 @@ public function testPositionWithDocumentSnapshot() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testSnapshotInFieldValue() { + $this->expectException('InvalidArgumentException'); + $snapshot = $this->prophesize(DocumentSnapshot::class); $this->query->startAt([$snapshot->reveal()]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidFieldValues() { + $this->expectException('InvalidArgumentException'); + $this->query->startAt('foo'); } @@ -1079,19 +1080,17 @@ public function testPositionInequalityFilter() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testBuildPositionTooManyCursorValues() { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy('foo')->endAt(['a','b']); } - /** - * @expectedException InvalidArgumentException - */ public function testBuildPositionOutOfBounds() { + $this->expectException('InvalidArgumentException'); + $ref = $this->prophesize(DocumentReference::class); $ref->name()->willReturn(self::QUERY_PARENT .'/whatev/john'); @@ -1102,36 +1101,34 @@ public function testBuildPositionOutOfBounds() $this->query->orderBy(Query::DOCUMENT_ID)->startAt([$ref->reveal()]); } - /** - * @expectedException InvalidArgumentException - */ public function testBuildPositionInvalidCursorType() { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy(Query::DOCUMENT_ID)->startAt([10]); } - /** - * @expectedException InvalidArgumentException - */ public function testBuildPositionInvalidDocumentName() { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy(Query::DOCUMENT_ID)->startAt(['a/b']); } /** - * @expectedException InvalidArgumentException * @dataProvider sentinels */ public function testBuildPositionInvalidSentinelValue($sentinel) { + $this->expectException('InvalidArgumentException'); + $this->query->orderBy(Query::DOCUMENT_ID)->startAt([$sentinel]); } - /** - * @expectedException InvalidArgumentException - */ public function testBuildPositionNestedChild() { + $this->expectException('InvalidArgumentException'); + $c = $this->prophesize(CollectionReference::class); $c->name()->willReturn(self::QUERY_PARENT .'/'. $this->queryFrom()[0]['collectionId'] .'/john'); diff --git a/Firestore/tests/Unit/SnapshotTraitTest.php b/Firestore/tests/Unit/SnapshotTraitTest.php index c29df8692bd8..e947050fda78 100644 --- a/Firestore/tests/Unit/SnapshotTraitTest.php +++ b/Firestore/tests/Unit/SnapshotTraitTest.php @@ -24,8 +24,9 @@ use Google\Cloud\Firestore\DocumentSnapshot; use Google\Cloud\Firestore\SnapshotTrait; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -33,6 +34,8 @@ */ class SnapshotTraitTest extends TestCase { + use ExpectException; + const PROJECT = 'example_project'; const DATABASE = '(default)'; const NAME = 'projects/example_project/databases/(default)/documents/a/b'; @@ -41,7 +44,7 @@ class SnapshotTraitTest extends TestCase private $mapper; private $impl; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->impl = TestHelpers::impl(SnapshotTrait::class); @@ -141,11 +144,10 @@ public function testGetSnapshotReadTime() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testGetSnapshotReadTimeInvalidReadTime() { + $this->expectException('InvalidArgumentException'); + $this->impl->call('getSnapshot', [ $this->connection->reveal(), self::NAME, @@ -153,11 +155,10 @@ public function testGetSnapshotReadTimeInvalidReadTime() ]); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testGetSnapshotNotFound() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $this->connection->batchGetDocuments([ 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), 'documents' => [self::NAME] diff --git a/Firestore/tests/Unit/TransactionTest.php b/Firestore/tests/Unit/TransactionTest.php index d62c6b13ae6c..9058d8c05c4b 100644 --- a/Firestore/tests/Unit/TransactionTest.php +++ b/Firestore/tests/Unit/TransactionTest.php @@ -27,7 +27,7 @@ use Google\Cloud\Firestore\QuerySnapshot; use Google\Cloud\Firestore\Transaction; use Google\Cloud\Firestore\ValueMapper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -46,7 +46,7 @@ class TransactionTest extends TestCase private $transaction; private $reference; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->valueMapper = new ValueMapper($this->connection->reveal(), false); diff --git a/Firestore/tests/Unit/ValueMapperTest.php b/Firestore/tests/Unit/ValueMapperTest.php index e254f5c5bcec..9462a1952b49 100644 --- a/Firestore/tests/Unit/ValueMapperTest.php +++ b/Firestore/tests/Unit/ValueMapperTest.php @@ -28,7 +28,8 @@ use Google\Cloud\Firestore\DocumentReference; use Google\Cloud\Firestore\ValueMapper; use Google\Protobuf\NullValue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group firestore @@ -36,12 +37,13 @@ */ class ValueMapperTest extends TestCase { + use ExpectException; use TimeTrait; private $connection; private $mapper; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->mapper = TestHelpers::stub(ValueMapper::class, [ @@ -178,11 +180,10 @@ public function testDecodeValuesIntAsObject() $this->assertEquals(15, $res['val']->get()); } - /** - * @expectedException RuntimeException - */ public function testDecodeValuesInvalidValue() { + $this->expectException('RuntimeException'); + $val = ['fooValue' => 15]; $res = $this->mapper->decodeValues(['val' => $val]); } @@ -355,19 +356,17 @@ function ($val) { ]; } - /** - * @expectedException RuntimeException - */ public function testEncodeValuesInvalidObject() { + $this->expectException('RuntimeException'); + $this->mapper->encodeValues(['val' => $this]); } - /** - * @expectedException RuntimeException - */ public function testEncodeValuesInvalidArray() { + $this->expectException('RuntimeException'); + $this->mapper->encodeValues(['val' => [ ['a'] ]]); @@ -393,11 +392,10 @@ public function testEncodeValidMultiValues($values) $this->assertEquals($values, $decoded['key']); } - /** - * @expectedException \RuntimeException - */ public function testEncodeInvalidMultiValue() { + $this->expectException('\RuntimeException'); + $this->mapper->encodeMultiValue([[['foo']]]); } } diff --git a/Firestore/tests/Unit/WriteBatchTest.php b/Firestore/tests/Unit/WriteBatchTest.php index 12b3bb7450f2..a2140b7a806c 100644 --- a/Firestore/tests/Unit/WriteBatchTest.php +++ b/Firestore/tests/Unit/WriteBatchTest.php @@ -26,8 +26,10 @@ use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; use Google\Cloud\Firestore\ValueMapper; use Google\Cloud\Firestore\WriteBatch; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches; /** * @group firestore @@ -35,6 +37,9 @@ */ class WriteBatchTest extends TestCase { + use ExpectException; + use ExpectExceptionMessageMatches; + const PROJECT = 'example_project'; const DATABASE = '(default)'; const DOCUMENT = 'projects/example_project/databases/(default)/documents/a/b'; @@ -43,7 +48,7 @@ class WriteBatchTest extends TestCase private $connection; private $batch; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->batch = TestHelpers::stub(WriteBatch::class, [ @@ -126,10 +131,11 @@ public function testUpdate($name, $ref) /** * @dataProvider updateBadInput - * @expectedException InvalidArgumentException */ public function testUpdateBadInput($data) { + $this->expectException('InvalidArgumentException'); + $this->batch->update(self::DOCUMENT, $data); } @@ -329,11 +335,10 @@ public function testSetSentinels($name, $ref) ]); } - /** - * @expectedException InvalidArgumentException - */ public function testSentinelsInArray() { + $this->expectException('InvalidArgumentException'); + $this->batch->set('name', [ 'foo' => [ FieldValue::serverTimestamp() @@ -363,12 +368,10 @@ public function testSentinelsAfterArrayNested() ]); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessageRegExp /Document transforms cannot contain/ - */ public function testSentinelCannotContainSentinel() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessageMatches('/Document transforms cannot contain/'); $this->batch->set('name', [ 'foo' => FieldValue::arrayRemove([FieldValue::arrayUnion([])]) ]); @@ -376,11 +379,12 @@ public function testSentinelCannotContainSentinel() /** * @dataProvider documents - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Delete cannot appear in data unless `$options['merge']` is set. */ public function testSetSentinelsDeleteRequiresMerge($name, $ref) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Delete cannot appear in data unless `$options[\'merge\']` is set.'); + $this->batch->set($ref, [ 'hello' => FieldValue::deleteField(), ]); @@ -447,11 +451,10 @@ public function documents() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testWriteUpdateTimePreconditionInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->batch->delete(self::DOCUMENT, [ 'precondition' => [ 'updateTime' => 'foobar' @@ -459,11 +462,10 @@ public function testWriteUpdateTimePreconditionInvalidType() ]); } - /** - * @expectedException InvalidArgumentException - */ public function testWritePreconditionMissingStuff() { + $this->expectException('InvalidArgumentException'); + $this->batch->delete(self::DOCUMENT, [ 'precondition' => ['foo' => 'bar'] ]); @@ -522,19 +524,17 @@ public function testRollback() $this->batch->rollback(); } - /** - * @expectedException RuntimeException - */ public function testRollbackFailsWithoutTransaction() { + $this->expectException('RuntimeException'); + $this->batch->rollback(); } - /** - * @expectedException InvalidArgumentException - */ public function testUpdateEmptyFails() { + $this->expectException('InvalidArgumentException'); + $this->batch->update(self::DOCUMENT, []); } diff --git a/Functions/composer.json b/Functions/composer.json index 34d13a847cf6..d33476b82b32 100644 --- a/Functions/composer.json +++ b/Functions/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Gaming/composer.json b/Gaming/composer.json index cb18fcaa5308..9682c1618332 100644 --- a/Gaming/composer.json +++ b/Gaming/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/GkeConnectGateway/composer.json b/GkeConnectGateway/composer.json index d3b349c674d5..a3b51101c99d 100644 --- a/GkeConnectGateway/composer.json +++ b/GkeConnectGateway/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/GkeHub/composer.json b/GkeHub/composer.json index e0fb3e1da905..acb1b12ab2bd 100644 --- a/GkeHub/composer.json +++ b/GkeHub/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Grafeas/composer.json b/Grafeas/composer.json index da426ec59257..94fa5da35977 100644 --- a/Grafeas/composer.json +++ b/Grafeas/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/IamCredentials/composer.json b/IamCredentials/composer.json index 740f9bc130cc..514b761bccb7 100644 --- a/IamCredentials/composer.json +++ b/IamCredentials/composer.json @@ -27,7 +27,8 @@ "google/common-protos": "^1.3.1||^2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Iap/composer.json b/Iap/composer.json index 24d818e2c6dd..5ce6a7f0a172 100644 --- a/Iap/composer.json +++ b/Iap/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Ids/composer.json b/Ids/composer.json index 908606bfc8fd..4b7be87e828b 100644 --- a/Ids/composer.json +++ b/Ids/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Iot/composer.json b/Iot/composer.json index 2b6344147613..958e3d199512 100644 --- a/Iot/composer.json +++ b/Iot/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Kms/composer.json b/Kms/composer.json index 8f71682f5c03..7165ae58cd24 100644 --- a/Kms/composer.json +++ b/Kms/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Language/composer.json b/Language/composer.json index 5d7a33f8dcd8..992e3349c2a7 100644 --- a/Language/composer.json +++ b/Language/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Language/phpunit-snippets.xml.dist b/Language/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Language/phpunit-snippets.xml.dist +++ b/Language/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Language/tests/Snippet/AnnotationTest.php b/Language/tests/Snippet/AnnotationTest.php index a93586f2ee80..9de26ec9c44d 100644 --- a/Language/tests/Snippet/AnnotationTest.php +++ b/Language/tests/Snippet/AnnotationTest.php @@ -32,7 +32,7 @@ class AnnotationTest extends SnippetTestCase private $annotation; private $info; - public function setUp() + public function set_up() { $this->info = [ 'categories' => [ diff --git a/Language/tests/Snippet/LanguageClientTest.php b/Language/tests/Snippet/LanguageClientTest.php index 00d39e35f799..28bb0d68a118 100644 --- a/Language/tests/Snippet/LanguageClientTest.php +++ b/Language/tests/Snippet/LanguageClientTest.php @@ -31,7 +31,7 @@ class LanguageClientTest extends SnippetTestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(LanguageClient::class); @@ -119,7 +119,7 @@ public function testAnalyzeSyntax() 'sentences' => [ [ 'text' => [ - 'beginOffset' => 1.0 + 'beginOffset' => '1.0' ] ] ] diff --git a/Language/tests/System/LanguageTestCase.php b/Language/tests/System/LanguageTestCase.php index 3cec58320b41..9b1c8ba4b0e1 100644 --- a/Language/tests/System/LanguageTestCase.php +++ b/Language/tests/System/LanguageTestCase.php @@ -22,14 +22,14 @@ use Google\Cloud\Language\LanguageClient; use Google\Cloud\PubSub\PubSubClient; use Google\Cloud\Storage\StorageClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class LanguageTestCase extends TestCase { protected static $client; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Language/tests/Unit/AnnotationTest.php b/Language/tests/Unit/AnnotationTest.php index 377fca2f3812..7ff98095a3b3 100644 --- a/Language/tests/Unit/AnnotationTest.php +++ b/Language/tests/Unit/AnnotationTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Language\Tests\Unit; use Google\Cloud\Language\Annotation; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group language @@ -30,7 +30,7 @@ class AnnotationTest extends TestCase private $info; private $token; - public function setUp() + public function set_up() { $this->entity = [ 'type' => 'PERSON' diff --git a/Language/tests/Unit/Connection/RestTest.php b/Language/tests/Unit/Connection/RestTest.php index a5c723f73ac2..9eb0839114c0 100644 --- a/Language/tests/Unit/Connection/RestTest.php +++ b/Language/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Language\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Language/tests/Unit/LanguageClientTest.php b/Language/tests/Unit/LanguageClientTest.php index 28a8641a0821..bece291d786b 100644 --- a/Language/tests/Unit/LanguageClientTest.php +++ b/Language/tests/Unit/LanguageClientTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Language\Connection\ConnectionInterface; use Google\Cloud\Language\LanguageClient; use Google\Cloud\Storage\StorageObject; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -33,7 +33,7 @@ class LanguageClientTest extends TestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(LanguageClient::class); $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/LifeSciences/composer.json b/LifeSciences/composer.json index 47ba59eb9f46..7a47df459361 100644 --- a/LifeSciences/composer.json +++ b/LifeSciences/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Logging/composer.json b/Logging/composer.json index 4008c794eaae..80ff0432549a 100644 --- a/Logging/composer.json +++ b/Logging/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Logging/phpunit-snippets.xml.dist b/Logging/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Logging/phpunit-snippets.xml.dist +++ b/Logging/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Logging/tests/Perf/LoggingPerfTest.php b/Logging/tests/Perf/LoggingPerfTest.php index ee749ddd18a8..041eb55595d2 100644 --- a/Logging/tests/Perf/LoggingPerfTest.php +++ b/Logging/tests/Perf/LoggingPerfTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Logging\LoggingClient; use Google\Cloud\Logging\PsrLogger; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group logging @@ -31,7 +31,7 @@ class LoggingPerfTest extends TestCase /* @var PsrLogger */ private $grpcClient; - public function setUp() + public function set_up() { $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $this->restLogger = LoggingClient::psrBatchLogger( diff --git a/Logging/tests/Snippet/LoggerTest.php b/Logging/tests/Snippet/LoggerTest.php index 49ace3ea085f..f3b07934d9d4 100644 --- a/Logging/tests/Snippet/LoggerTest.php +++ b/Logging/tests/Snippet/LoggerTest.php @@ -36,7 +36,7 @@ class LoggerTest extends SnippetTestCase private $connection; private $logger; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->logger = TestHelpers::stub(Logger::class, [ diff --git a/Logging/tests/Snippet/LoggingClientTest.php b/Logging/tests/Snippet/LoggingClientTest.php index eb983bba2ecd..c28a2e6fc17c 100644 --- a/Logging/tests/Snippet/LoggingClientTest.php +++ b/Logging/tests/Snippet/LoggingClientTest.php @@ -36,7 +36,7 @@ class LoggingClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(LoggingClient::class); diff --git a/Logging/tests/Snippet/MetricTest.php b/Logging/tests/Snippet/MetricTest.php index 11620b70b214..df798f4de828 100644 --- a/Logging/tests/Snippet/MetricTest.php +++ b/Logging/tests/Snippet/MetricTest.php @@ -34,7 +34,7 @@ class MetricTest extends SnippetTestCase private $connection; private $metric; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->metric = TestHelpers::stub(Metric::class, [ diff --git a/Logging/tests/Snippet/PsrLoggerTest.php b/Logging/tests/Snippet/PsrLoggerTest.php index 5f5252271893..6da3ed5d48a9 100644 --- a/Logging/tests/Snippet/PsrLoggerTest.php +++ b/Logging/tests/Snippet/PsrLoggerTest.php @@ -32,7 +32,7 @@ class PsrLoggerTest extends SnippetTestCase private $connection; private $psr; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Logging/tests/Snippet/SinkTest.php b/Logging/tests/Snippet/SinkTest.php index 8e56b6f46a69..268329548144 100644 --- a/Logging/tests/Snippet/SinkTest.php +++ b/Logging/tests/Snippet/SinkTest.php @@ -34,7 +34,7 @@ class SinkTest extends SnippetTestCase private $connection; private $sink; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->sink = TestHelpers::stub(Sink::class, [ diff --git a/Logging/tests/System/LoggingTestCase.php b/Logging/tests/System/LoggingTestCase.php index ceca5d138724..c1ec64e2f1a7 100644 --- a/Logging/tests/System/LoggingTestCase.php +++ b/Logging/tests/System/LoggingTestCase.php @@ -37,7 +37,7 @@ class LoggingTestCase extends SystemTestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -45,7 +45,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Logging/tests/System/ManageSinksTest.php b/Logging/tests/System/ManageSinksTest.php index 6b3d130cea13..c53fd959fd28 100644 --- a/Logging/tests/System/ManageSinksTest.php +++ b/Logging/tests/System/ManageSinksTest.php @@ -77,7 +77,7 @@ public function testCreateSink($client, $destination) public function createSinkProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); $bucket = self::$bucket; $bucket->acl()->add('group-cloud-logs@google.com', 'OWNER'); $bucketDest = sprintf('storage.googleapis.com/%s', $bucket->name()); diff --git a/Logging/tests/Unit/Connection/GrpcTest.php b/Logging/tests/Unit/Connection/GrpcTest.php index c5bc92e87252..01799339bca1 100644 --- a/Logging/tests/Unit/Connection/GrpcTest.php +++ b/Logging/tests/Unit/Connection/GrpcTest.php @@ -25,7 +25,7 @@ use Google\Cloud\Logging\V2\LogMetric; use Google\Cloud\Logging\V2\LogSink; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group logging @@ -37,7 +37,7 @@ class GrpcTest extends TestCase private $requestWrapper; private $successMessage; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Logging/tests/Unit/Connection/RestTest.php b/Logging/tests/Unit/Connection/RestTest.php index b36dcd39abdf..4e05645c3d28 100644 --- a/Logging/tests/Unit/Connection/RestTest.php +++ b/Logging/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Logging\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Logging/tests/Unit/LoggerTest.php b/Logging/tests/Unit/LoggerTest.php index 09732c5e79b7..d3d6aa1e805f 100644 --- a/Logging/tests/Unit/LoggerTest.php +++ b/Logging/tests/Unit/LoggerTest.php @@ -20,14 +20,17 @@ use Google\Cloud\Core\Timestamp; use Google\Cloud\Logging\Connection\ConnectionInterface; use Google\Cloud\Logging\Logger; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group logging */ class LoggerTest extends TestCase { + use ExpectException; + private $connection; private $formattedName = 'projects/myProjectId/logs/myLog'; private $logName = 'myLog'; @@ -38,7 +41,7 @@ class LoggerTest extends TestCase private $microtime = 315532800.000000; private $formattedTimestamp = '1980-01-01T00:00:00.000000Z'; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } @@ -187,11 +190,10 @@ public function entryProvider() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testCreateEntryThrowsExceptionWithInvalidData() { + $this->expectException('\InvalidArgumentException'); + $logger = $this->getLogger($this->connection); $entry = $logger->entry(123123); } diff --git a/Logging/tests/Unit/LoggingClientTest.php b/Logging/tests/Unit/LoggingClientTest.php index bceca6cfaaba..c37c170a091d 100644 --- a/Logging/tests/Unit/LoggingClientTest.php +++ b/Logging/tests/Unit/LoggingClientTest.php @@ -29,8 +29,7 @@ use Google\Cloud\Logging\Metric; use Google\Cloud\Logging\PsrLogger; use Google\Cloud\Logging\Sink; -use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_Assert; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -48,7 +47,7 @@ class LoggingClientTest extends TestCase public $textPayload = 'aPayload'; public $client; - public function setUp() + public function set_up() { $this->formattedProjectId = "projects/$this->projectId"; $this->connection = $this->prophesize(ConnectionInterface::class); @@ -331,11 +330,13 @@ public function testOptionsArePassedToPsrLogger() $this->client->___setProperty('connection', $this->connection->reveal()); $psrLogger = $this->client->psrLogger('myLogger', $options); - + $reflection = new \ReflectionClass($psrLogger); foreach ($options as $name => $value) { + $attr = $reflection->getProperty($name); + $attr->setAccessible(true); $this->assertEquals( $value, - PHPUnit_Framework_Assert::readAttribute($psrLogger, $name), + $attr->getValue($psrLogger), "$name assertion failed." ); } diff --git a/Logging/tests/Unit/MetricTest.php b/Logging/tests/Unit/MetricTest.php index 1341a697884e..ef46989fef02 100644 --- a/Logging/tests/Unit/MetricTest.php +++ b/Logging/tests/Unit/MetricTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Logging\Metric; use Google\Cloud\Logging\Connection\ConnectionInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group logging @@ -36,7 +36,7 @@ class MetricTest extends TestCase 'description' => 'wow a description' ]; - public function setUp() + public function set_up() { $this->formattedName = "projects/$this->projectId/metrics/$this->metricName"; $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Logging/tests/Unit/PsrLoggerBatchTest.php b/Logging/tests/Unit/PsrLoggerBatchTest.php index 437036598673..38c98537edf0 100644 --- a/Logging/tests/Unit/PsrLoggerBatchTest.php +++ b/Logging/tests/Unit/PsrLoggerBatchTest.php @@ -26,13 +26,16 @@ use Google\Cloud\Logging\PsrLogger; use GuzzleHttp\Psr7\Response; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group logging */ class PsrLoggerBatchTest extends TestCase { + use AssertStringContains; + const LOG_NAME = 'my-log'; private $runner; @@ -41,7 +44,7 @@ class PsrLoggerBatchTest extends TestCase private static $logName; private static $entry; - public function setUp() + public function set_up() { $this->runner = $this->prophesize(BatchRunner::class); $this->logger = $this->prophesize(Logger::class); @@ -80,7 +83,7 @@ public function testSend( if ($expectedOutput === false) { $this->assertEmpty($output); } else { - $this->assertContains($expectedOutput, $output); + $this->assertStringContainsString($expectedOutput, $output); } } diff --git a/Logging/tests/Unit/PsrLoggerCompatibilityTest.php b/Logging/tests/Unit/PsrLoggerCompatibilityTest.php index 0dcf6697ca8d..6deb107cb9b0 100644 --- a/Logging/tests/Unit/PsrLoggerCompatibilityTest.php +++ b/Logging/tests/Unit/PsrLoggerCompatibilityTest.php @@ -22,21 +22,20 @@ use Google\Cloud\Logging\PsrLogger; use Psr\Log\Test\LoggerInterfaceTest; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group logging */ class PsrLoggerCompatibilityTest extends LoggerInterfaceTest { - public static $logs = []; + use ExpectException; - public function setUp() - { - self::$logs = []; - } + public static $logs = []; public function getLogger() { + self::$logs = []; $connection = $this->prophesize(ConnectionInterface::class); $connection->writeEntries(Argument::any()) ->will(function ($entries) { @@ -58,6 +57,14 @@ public function getLogger() return new PsrLogger($logger); } + public function testThrowsOnInvalidLevel() + { + $this->expectException('\Psr\Log\InvalidArgumentException'); + + $logger = $this->getLogger(); + $logger->log('invalid level', 'Foo'); + } + public function getLogs() { return self::$logs; diff --git a/Logging/tests/Unit/PsrLoggerTest.php b/Logging/tests/Unit/PsrLoggerTest.php index 5857092d94e9..bea51a9ca401 100644 --- a/Logging/tests/Unit/PsrLoggerTest.php +++ b/Logging/tests/Unit/PsrLoggerTest.php @@ -24,14 +24,16 @@ use Google\Cloud\Logging\PsrLogger; use Google\Cloud\Logging\Connection\ConnectionInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_Assert; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group logging */ class PsrLoggerTest extends TestCase { + use ExpectException; + public $connection; public $formattedName; public $logName = 'myLog'; @@ -40,7 +42,7 @@ class PsrLoggerTest extends TestCase public $resource = ['type' => 'global']; public $severity = 'ALERT'; - public function setUp() + public function set_up() { $this->formattedName = "projects/$this->projectId/logs/$this->logName"; $this->connection = $this->prophesize(ConnectionInterface::class); @@ -176,11 +178,10 @@ public function testOverridePsrLoggerDefaults() ); } - /** - * @expectedException Psr\Log\InvalidArgumentException - */ public function testLogThrowsExceptionWithInvalidLevel() { + $this->expectException('Psr\Log\InvalidArgumentException'); + $psrLogger = $this->getPsrLogger($this->connection); $psrLogger->log('INVALID-LEVEL', $this->textPayload); } @@ -244,41 +245,33 @@ public function testSerializesCorrectly() $options['batchMethod'] = 'writeBatch'; $options['logName'] = $this->logName; $psrLogger = unserialize(serialize($psrLogger)); + $reflection = new \ReflectionClass($psrLogger); + $debugOutpoutResourceAttr = $reflection->getProperty('debugOutputResource'); + $debugOutpoutResourceAttr->setAccessible(true); $debugResourceMetadata = stream_get_meta_data( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'debugOutputResource') + $debugOutpoutResourceAttr->getValue($psrLogger) ); $expectedDebugResourceMetadata = stream_get_meta_data($expectedDebugResource); $this->assertEquals($debugResourceMetadata['uri'], $expectedDebugResourceMetadata['uri']); $this->assertEquals($debugResourceMetadata['mode'], $expectedDebugResourceMetadata['mode']); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'metadataProvider'), - $options['metadataProvider'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'batchEnabled'), - $options['batchEnabled'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'debugOutput'), - $options['debugOutput'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'clientConfig'), - $options['clientConfig'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'messageKey'), - $options['messageKey'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'batchMethod'), - $options['batchMethod'] - ); - $this->assertEquals( - PHPUnit_Framework_Assert::readAttribute($psrLogger, 'logName'), - $options['logName'] - ); + $attributes = [ + 'metadataProvider', + 'batchEnabled', + 'debugOutput', + 'clientConfig', + 'messageKey' , + 'batchMethod', + 'logName' + ]; + foreach ($attributes as $attributeName) { + $attr = $reflection->getProperty($attributeName); + $attr->setAccessible(true); + $this->assertEquals( + $attr->getValue($psrLogger), + $options[$attributeName] + ); + } } private function expectLogWithExceptionInContext($throwable) diff --git a/Logging/tests/Unit/SinkTest.php b/Logging/tests/Unit/SinkTest.php index 1329fc939f6d..d1cce66cb470 100644 --- a/Logging/tests/Unit/SinkTest.php +++ b/Logging/tests/Unit/SinkTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Logging\Sink; use Google\Cloud\Logging\Connection\ConnectionInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group logging @@ -36,7 +36,7 @@ class SinkTest extends TestCase 'destination' => 'wow a destination' ]; - public function setUp() + public function set_up() { $this->formattedName = "projects/$this->projectId/sinks/$this->sinkName"; $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/ManagedIdentities/composer.json b/ManagedIdentities/composer.json index 35743a969159..4751c07be24d 100644 --- a/ManagedIdentities/composer.json +++ b/ManagedIdentities/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/MediaTranslation/composer.json b/MediaTranslation/composer.json index 7f3b104715ec..b9df42526f44 100644 --- a/MediaTranslation/composer.json +++ b/MediaTranslation/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Memcache/composer.json b/Memcache/composer.json index a66bc2695023..93c4d8409cb6 100644 --- a/Memcache/composer.json +++ b/Memcache/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Monitoring/composer.json b/Monitoring/composer.json index 7cec4a8f3f34..8b76f8d522df 100644 --- a/Monitoring/composer.json +++ b/Monitoring/composer.json @@ -7,7 +7,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/NetworkConnectivity/composer.json b/NetworkConnectivity/composer.json index a91f005c11c6..973dcf18fa64 100644 --- a/NetworkConnectivity/composer.json +++ b/NetworkConnectivity/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/NetworkManagement/composer.json b/NetworkManagement/composer.json index 5475988ab6fd..11ab23a2596b 100644 --- a/NetworkManagement/composer.json +++ b/NetworkManagement/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/NetworkSecurity/composer.json b/NetworkSecurity/composer.json index 8efd5ba4ebf1..2169ec3b9bac 100644 --- a/NetworkSecurity/composer.json +++ b/NetworkSecurity/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.9.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Notebooks/composer.json b/Notebooks/composer.json index f903b1e2e628..11f760247d73 100644 --- a/Notebooks/composer.json +++ b/Notebooks/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/OrchestrationAirflow/composer.json b/OrchestrationAirflow/composer.json index cbc4273a269d..ab4c56e6ca53 100644 --- a/OrchestrationAirflow/composer.json +++ b/OrchestrationAirflow/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/OrgPolicy/composer.json b/OrgPolicy/composer.json index c29f2fb853ff..0ee7bd31654a 100644 --- a/OrgPolicy/composer.json +++ b/OrgPolicy/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/OsConfig/composer.json b/OsConfig/composer.json index 403b9fecf84d..d5653527b140 100644 --- a/OsConfig/composer.json +++ b/OsConfig/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/OsLogin/composer.json b/OsLogin/composer.json index b12e7cbaebcb..78bc0e6ac0ca 100644 --- a/OsLogin/composer.json +++ b/OsLogin/composer.json @@ -21,7 +21,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/OsLogin/tests/System/V1/OsLoginServiceClientTest.php b/OsLogin/tests/System/V1/OsLoginServiceClientTest.php index 6f7e42240568..0fcc007fa368 100644 --- a/OsLogin/tests/System/V1/OsLoginServiceClientTest.php +++ b/OsLogin/tests/System/V1/OsLoginServiceClientTest.php @@ -20,7 +20,7 @@ use Google\Auth\CredentialsLoader; use Google\Cloud\OsLogin\V1\OsLoginServiceClient; use Google\Cloud\OsLogin\V1\LoginProfile; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class OsLoginServiceClientTest extends TestCase { @@ -31,7 +31,7 @@ class OsLoginServiceClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -39,7 +39,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/OsLogin/tests/System/V1beta/OsLoginServiceClientTest.php b/OsLogin/tests/System/V1beta/OsLoginServiceClientTest.php index 74353cdb044e..b80f78e125d8 100644 --- a/OsLogin/tests/System/V1beta/OsLoginServiceClientTest.php +++ b/OsLogin/tests/System/V1beta/OsLoginServiceClientTest.php @@ -20,7 +20,7 @@ use Google\Auth\CredentialsLoader; use Google\Cloud\OsLogin\V1beta\OsLoginServiceClient; use Google\Cloud\OsLogin\V1beta\LoginProfile; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class OsLoginServiceClientTest extends TestCase { @@ -31,7 +31,7 @@ class OsLoginServiceClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -39,7 +39,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/PolicyTroubleshooter/composer.json b/PolicyTroubleshooter/composer.json index 20b4b99e6487..e394c57dfd04 100644 --- a/PolicyTroubleshooter/composer.json +++ b/PolicyTroubleshooter/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/PrivateCatalog/composer.json b/PrivateCatalog/composer.json index 4cd6fec54636..7e86622ed77d 100644 --- a/PrivateCatalog/composer.json +++ b/PrivateCatalog/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Profiler/composer.json b/Profiler/composer.json index bb210592e416..b3846d23a9a3 100644 --- a/Profiler/composer.json +++ b/Profiler/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/PubSub/composer.json b/PubSub/composer.json index e6162c73b99a..0ecfa63670c4 100644 --- a/PubSub/composer.json +++ b/PubSub/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6" diff --git a/PubSub/phpunit-snippets.xml.dist b/PubSub/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/PubSub/phpunit-snippets.xml.dist +++ b/PubSub/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/PubSub/tests/Snippet/BatchPublisherTest.php b/PubSub/tests/Snippet/BatchPublisherTest.php index 17b55cae428c..4327d29e6a1f 100644 --- a/PubSub/tests/Snippet/BatchPublisherTest.php +++ b/PubSub/tests/Snippet/BatchPublisherTest.php @@ -30,7 +30,7 @@ class BatchPublisherTest extends SnippetTestCase { private $batchPublisher; - public function setUp() + public function set_up() { $this->batchPublisher = $this->prophesize(BatchPublisher::class); $this->batchPublisher->publish([ diff --git a/PubSub/tests/Snippet/MessageBuilderTest.php b/PubSub/tests/Snippet/MessageBuilderTest.php index 680be593aafd..27bae635d344 100644 --- a/PubSub/tests/Snippet/MessageBuilderTest.php +++ b/PubSub/tests/Snippet/MessageBuilderTest.php @@ -32,7 +32,7 @@ class MessageBuilderTest extends SnippetTestCase { private $builder; - public function setUp() + public function set_up() { $this->builder = new MessageBuilder; } diff --git a/PubSub/tests/Snippet/MessageTest.php b/PubSub/tests/Snippet/MessageTest.php index 1f4130942dbe..f88cdf8799ab 100644 --- a/PubSub/tests/Snippet/MessageTest.php +++ b/PubSub/tests/Snippet/MessageTest.php @@ -24,12 +24,15 @@ use Google\Cloud\PubSub\PubSubClient; use Google\Cloud\PubSub\Subscription; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group pubsub */ class MessageTest extends SnippetTestCase { + use AssertIsType; + const SUBSCRIPTION = 'projects/my-awesome-project/subscriptions/my-new-subscription'; const TOPIC = 'projects/my-awesome-project/topics/topic-name'; @@ -37,7 +40,7 @@ class MessageTest extends SnippetTestCase private $metadata; private $message; - public function setUp() + public function set_up() { $this->msg = [ 'data' => 'hello world', @@ -183,6 +186,6 @@ public function testInfo() $snippet->addLocal('message', $this->message); $res = $snippet->invoke('info'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } } diff --git a/PubSub/tests/Snippet/PubSubClientTest.php b/PubSub/tests/Snippet/PubSubClientTest.php index 99689a0fb716..566796cc4b3c 100644 --- a/PubSub/tests/Snippet/PubSubClientTest.php +++ b/PubSub/tests/Snippet/PubSubClientTest.php @@ -45,7 +45,7 @@ class PubSubClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(PubSubClient::class, [['transport' => 'rest']]); diff --git a/PubSub/tests/Snippet/SchemaTest.php b/PubSub/tests/Snippet/SchemaTest.php index 473f12de5d27..cea55b4031cf 100644 --- a/PubSub/tests/Snippet/SchemaTest.php +++ b/PubSub/tests/Snippet/SchemaTest.php @@ -36,7 +36,7 @@ class SchemaTest extends SnippetTestCase private $connection; private $schema; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->schema = TestHelpers::stub(Schema::class, [ diff --git a/PubSub/tests/Snippet/SnapshotTest.php b/PubSub/tests/Snippet/SnapshotTest.php index c0c0bbe7d7e5..b9c1d583dda1 100644 --- a/PubSub/tests/Snippet/SnapshotTest.php +++ b/PubSub/tests/Snippet/SnapshotTest.php @@ -36,7 +36,7 @@ class SnapshotTest extends SnippetTestCase private $connection; private $snapshot; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->snapshot = TestHelpers::stub(Snapshot::class, [ diff --git a/PubSub/tests/Snippet/SubscriptionTest.php b/PubSub/tests/Snippet/SubscriptionTest.php index 9fe4469beb83..867c6675c98f 100644 --- a/PubSub/tests/Snippet/SubscriptionTest.php +++ b/PubSub/tests/Snippet/SubscriptionTest.php @@ -26,12 +26,15 @@ use Google\Cloud\PubSub\PubSubClient; use Google\Cloud\PubSub\Subscription; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class SubscriptionTest extends SnippetTestCase { + use ExpectException; + const TOPIC = 'projects/my-awesome-project/topics/my-new-topic'; const SUBSCRIPTION = 'projects/my-awesome-project/subscriptions/my-new-subscription'; @@ -39,7 +42,7 @@ class SubscriptionTest extends SnippetTestCase private $subscription; private $pubsub; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->subscription = TestHelpers::stub(Subscription::class, [ @@ -92,11 +95,10 @@ public function testAuthenticatedPush() $this->assertEquals('Authenticated using ' . $email, $res->output()); } - /** - * @expectedException \RuntimeException - */ public function testAuthenticatedPushFails() { + $this->expectException('\RuntimeException'); + $authToken = 'foobar'; $token = $this->prophesize(AccessToken::class); $token->verify($authToken) diff --git a/PubSub/tests/Snippet/TopicTest.php b/PubSub/tests/Snippet/TopicTest.php index 302fb02855bb..315200e83bd3 100644 --- a/PubSub/tests/Snippet/TopicTest.php +++ b/PubSub/tests/Snippet/TopicTest.php @@ -40,7 +40,7 @@ class TopicTest extends SnippetTestCase private $pubsub; private $topic; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->pubsub = TestHelpers::stub(PubSubClient::class, [ diff --git a/PubSub/tests/System/ManageIAMPoliciesTest.php b/PubSub/tests/System/ManageIAMPoliciesTest.php index c3623bf7ce51..0a5268d37b36 100644 --- a/PubSub/tests/System/ManageIAMPoliciesTest.php +++ b/PubSub/tests/System/ManageIAMPoliciesTest.php @@ -23,9 +23,9 @@ */ class ManageIAMPoliciesTest extends PubSubTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::skipIfEmulatorUsed('Emulator does not implement IAM functions.'); } diff --git a/PubSub/tests/System/PubSubTestCase.php b/PubSub/tests/System/PubSubTestCase.php index 1fc0c201554c..2791bdf839b8 100644 --- a/PubSub/tests/System/PubSubTestCase.php +++ b/PubSub/tests/System/PubSubTestCase.php @@ -32,7 +32,7 @@ class PubSubTestCase extends SystemTestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); $result = [ 'grpc' => [self::$grpcClient], @@ -43,7 +43,7 @@ public function clientProvider() return $result; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/PubSub/tests/System/SchemaTest.php b/PubSub/tests/System/SchemaTest.php index 3c15fa13e0ac..40611b01a177 100644 --- a/PubSub/tests/System/SchemaTest.php +++ b/PubSub/tests/System/SchemaTest.php @@ -30,7 +30,7 @@ */ class SchemaTest extends PubSubTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { self::skipIfEmulatorUsed( "schema tests are not supported when using service emulation" diff --git a/PubSub/tests/Unit/Connection/GrpcTest.php b/PubSub/tests/Unit/Connection/GrpcTest.php index 4dea461a77f5..3a764e531238 100644 --- a/PubSub/tests/Unit/Connection/GrpcTest.php +++ b/PubSub/tests/Unit/Connection/GrpcTest.php @@ -35,7 +35,7 @@ use Google\Protobuf\Duration; use Google\Protobuf\FieldMask; use Google\Protobuf\Timestamp; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -57,7 +57,7 @@ class GrpcTest extends TestCase private $snapshotName = 'projects/foo/snapshots/bar'; private $pageSize = ['pageSize' => 3]; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/PubSub/tests/Unit/Connection/RestTest.php b/PubSub/tests/Unit/Connection/RestTest.php index 80275188aca0..34a1b4563541 100644 --- a/PubSub/tests/Unit/Connection/RestTest.php +++ b/PubSub/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\PubSub\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -37,7 +37,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/PubSub/tests/Unit/IncomingMessageTraitTest.php b/PubSub/tests/Unit/IncomingMessageTraitTest.php index 20f8cc0a1fd7..089556f23bfd 100644 --- a/PubSub/tests/Unit/IncomingMessageTraitTest.php +++ b/PubSub/tests/Unit/IncomingMessageTraitTest.php @@ -22,19 +22,22 @@ use Google\Cloud\PubSub\IncomingMessageTrait; use Google\Cloud\PubSub\Message; use Google\Cloud\PubSub\Subscription; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class IncomingMessageTraitTest extends TestCase { + use ExpectException; + const PROJECT = 'my-project'; private $connection; private $stub; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->stub = TestHelpers::impl(IncomingMessageTrait::class); @@ -59,11 +62,10 @@ public function testMessageFactory() $this->assertEquals('hello world', $message->data()); } - /** - * @expectedException Google\Cloud\Core\Exception\GoogleException - */ public function testInvalidMessage() { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $this->stub->call( 'messageFactory', [ diff --git a/PubSub/tests/Unit/MessageBuilderTest.php b/PubSub/tests/Unit/MessageBuilderTest.php index 8f73dda3216e..46b67334f06d 100644 --- a/PubSub/tests/Unit/MessageBuilderTest.php +++ b/PubSub/tests/Unit/MessageBuilderTest.php @@ -19,6 +19,7 @@ use Google\Cloud\PubSub\MessageBuilder; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub @@ -26,6 +27,8 @@ */ class MessageBuilderTest extends TestCase { + use ExpectException; + public function testSetters() { $expected = [ @@ -47,11 +50,10 @@ public function testSetters() $this->assertEquals($expected, $builder->build()->toArray()); } - /** - * @expectedException \BadMethodCallException - */ public function testMissingData() { + $this->expectException('\BadMethodCallException'); + (new MessageBuilder)->build(); } } diff --git a/PubSub/tests/Unit/MessageTest.php b/PubSub/tests/Unit/MessageTest.php index beaa830cb739..f3748f0b53ee 100644 --- a/PubSub/tests/Unit/MessageTest.php +++ b/PubSub/tests/Unit/MessageTest.php @@ -19,18 +19,21 @@ use Google\Cloud\PubSub\Message; use Google\Cloud\PubSub\Subscription; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group pubsub */ class MessageTest extends TestCase { + use AssertIsType; + private $message; private $time = '2016-09-27T13:21:30.242Z'; - public function setUp() + public function set_up() { $this->message = new Message([ 'data' => 'hello world', @@ -112,8 +115,8 @@ public function testSubscription() public function testInfo() { - $this->assertInternalType('array', $this->message->info()); - $this->assertInternalType('array', $this->message->info()['message']); + $this->assertIsArray($this->message->info()); + $this->assertIsArray($this->message->info()['message']); $this->assertInstanceOf(Subscription::class, $this->message->info()['subscription']); $this->assertEquals(1234, $this->message->info()['ackId']); } diff --git a/PubSub/tests/Unit/PubSubClientTest.php b/PubSub/tests/Unit/PubSubClientTest.php index db2650befb5f..77092f48f6d9 100644 --- a/PubSub/tests/Unit/PubSubClientTest.php +++ b/PubSub/tests/Unit/PubSubClientTest.php @@ -34,14 +34,16 @@ use Google\Cloud\PubSub\V1\PublisherClient; use Google\Cloud\PubSub\V1\SchemaServiceClient; use Google\Cloud\PubSub\V1\SubscriberClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class PubSubClientTest extends TestCase { + use ExpectException; use GrpcTestTrait; const PROJECT = 'project'; @@ -51,7 +53,7 @@ class PubSubClientTest extends TestCase private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); @@ -500,11 +502,10 @@ public function testValidateSchema() $this->assertEquals(['foo' => 'bar'], $res); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testValidateSchemaThrowsException() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $this->connection->validateSchema(Argument::any()) ->shouldBeCalled() ->willThrow(new BadRequestException('foo')); @@ -565,11 +566,10 @@ public function messagesToValidate() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testValidateMessageInvalidSchema() { + $this->expectException('\InvalidArgumentException'); + $this->client->validateMessage(1, 'foo', 'bar'); } diff --git a/PubSub/tests/Unit/ResourceNameTraitTest.php b/PubSub/tests/Unit/ResourceNameTraitTest.php index d99ddebc51ee..bf8a6db404fd 100644 --- a/PubSub/tests/Unit/ResourceNameTraitTest.php +++ b/PubSub/tests/Unit/ResourceNameTraitTest.php @@ -19,16 +19,19 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\PubSub\ResourceNameTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class ResourceNameTraitTest extends TestCase { + use ExpectException; + private $trait; - public function setUp() + public function set_up() { $this->trait = TestHelpers::impl(ResourceNameTrait::class); } @@ -63,11 +66,10 @@ public function testPluckSubscriptionName() $this->assertEquals('bar', $res); } - /** - * @expectedException \InvalidArgumentException - */ public function testPluckNameInvalidFormat() { + $this->expectException('\InvalidArgumentException'); + $this->trait->call('pluckName', ['lame', 'bar']); } @@ -92,11 +94,10 @@ public function testFormatSubscriptionName() $this->assertEquals('projects/my-project/subscriptions/foo', $res); } - /** - * @expectedException \InvalidArgumentException - */ public function testFormatNameInvalidType() { + $this->expectException('\InvalidArgumentException'); + $this->trait->call('formatName', ['lame', 'foo']); } @@ -139,11 +140,10 @@ public function testIsFullyQualifiedSubscriptionName() ])); } - /** - * @expectedException \InvalidArgumentException - */ public function testIsFullyQualifiedNameInvalidType() { + $this->expectException('\InvalidArgumentException'); + $this->trait->call('isFullyQualifiedName', ['lame', 'foo']); } } diff --git a/PubSub/tests/Unit/SchemaTest.php b/PubSub/tests/Unit/SchemaTest.php index 09c8981d0723..bad10bc09e33 100644 --- a/PubSub/tests/Unit/SchemaTest.php +++ b/PubSub/tests/Unit/SchemaTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\PubSub\Connection\ConnectionInterface; use Google\Cloud\PubSub\Schema; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group pubsub @@ -34,7 +34,7 @@ class SchemaTest extends TestCase private $connection; private $schema; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->schema = TestHelpers::stub(Schema::class, [ diff --git a/PubSub/tests/Unit/SnapshotTest.php b/PubSub/tests/Unit/SnapshotTest.php index 3f0160f62c4d..b113b632d3d2 100644 --- a/PubSub/tests/Unit/SnapshotTest.php +++ b/PubSub/tests/Unit/SnapshotTest.php @@ -22,21 +22,24 @@ use Google\Cloud\PubSub\Snapshot; use Google\Cloud\PubSub\Subscription; use Google\Cloud\PubSub\Topic; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class SnapshotTest extends TestCase { + use ExpectException; + const PROJECT = 'my-project'; const SNAPSHOT_ID = 'snapshot'; private $connection; private $snapshot; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->snapshot = TestHelpers::stub(Snapshot::class, [ @@ -94,11 +97,10 @@ public function testCreate() $this->snapshot->create(); } - /** - * @expectedException BadMethodCallException - */ public function testCreateWithoutSubscription() { + $this->expectException('BadMethodCallException'); + $this->snapshot->create(); } diff --git a/PubSub/tests/Unit/SubscriptionTest.php b/PubSub/tests/Unit/SubscriptionTest.php index 7aa0257eb4ad..3a494c7304b3 100644 --- a/PubSub/tests/Unit/SubscriptionTest.php +++ b/PubSub/tests/Unit/SubscriptionTest.php @@ -27,8 +27,9 @@ use Google\Cloud\PubSub\Snapshot; use Google\Cloud\PubSub\Subscription; use Google\Cloud\PubSub\Topic; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub @@ -36,6 +37,8 @@ */ class SubscriptionTest extends TestCase { + use ExpectException; + const PROJECT = 'project-id'; const SUBSCRIPTION = 'projects/project-id/subscriptions/subscription-name'; const TOPIC = 'projects/project-id/topics/topic-name'; @@ -43,7 +46,7 @@ class SubscriptionTest extends TestCase private $subscription; private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->subscription = TestHelpers::stub(Subscription::class, [ @@ -92,11 +95,10 @@ public function testCreate() $this->assertEquals($sub['topic'], self::TOPIC); } - /** - * @expectedException InvalidArgumentException - */ public function testCreateWithoutTopicName() { + $this->expectException('InvalidArgumentException'); + $subscription = new Subscription( $this->connection->reveal(), 'project-id', @@ -441,11 +443,10 @@ public function testAcknowledgeBatch() $this->subscription->acknowledgeBatch($messages, ['foo' => 'bar']); } - /** - * @expectedException InvalidArgumentException - */ public function testAcknowledgeBatchInvalidArgument() { + $this->expectException('InvalidArgumentException'); + $this->subscription->acknowledgeBatch(['foo']); } @@ -491,11 +492,10 @@ public function testModifyAckDeadlineBatch() $this->subscription->modifyAckDeadlineBatch($messages, $seconds, ['foo' => 'bar']); } - /** - * @expectedException InvalidArgumentException - */ public function testModifyAckDeadlineBatchInvalidArgument() { + $this->expectException('InvalidArgumentException'); + $this->subscription->modifyAckDeadlineBatch(['foo'], 100); } diff --git a/PubSub/tests/Unit/TopicTest.php b/PubSub/tests/Unit/TopicTest.php index e7182aebc8d7..778da5947e32 100644 --- a/PubSub/tests/Unit/TopicTest.php +++ b/PubSub/tests/Unit/TopicTest.php @@ -25,20 +25,23 @@ use Google\Cloud\PubSub\Connection\ConnectionInterface; use Google\Cloud\PubSub\Subscription; use Google\Cloud\PubSub\Topic; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group pubsub */ class TopicTest extends TestCase { + use ExpectException; + const TOPIC = 'projects/project-name/topics/topic-name'; private $topic; private $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->topic = TestHelpers::stub(Topic::class, [ @@ -245,11 +248,10 @@ public function testPublishBatchUnencoded() $res = $this->topic->publishBatch([$message], ['foo' => 'bar', 'encode' => false]); } - /** - * @expectedException InvalidArgumentException - */ public function testPublishMalformedMessage() { + $this->expectException('InvalidArgumentException'); + $message = [ 'key' => 'val' ]; diff --git a/RecaptchaEnterprise/composer.json b/RecaptchaEnterprise/composer.json index 35cfb7b985ee..b9d4edbd315b 100644 --- a/RecaptchaEnterprise/composer.json +++ b/RecaptchaEnterprise/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/RecommendationEngine/composer.json b/RecommendationEngine/composer.json index a422c2dfd426..1c20b357b7c6 100644 --- a/RecommendationEngine/composer.json +++ b/RecommendationEngine/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Recommender/composer.json b/Recommender/composer.json index 7bf6aca738b9..f0b7aa3c9301 100644 --- a/Recommender/composer.json +++ b/Recommender/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Redis/composer.json b/Redis/composer.json index 7c98062189f9..3f3124051cf6 100644 --- a/Redis/composer.json +++ b/Redis/composer.json @@ -22,7 +22,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Redis/tests/System/V1/CloudRedisClientTest.php b/Redis/tests/System/V1/CloudRedisClientTest.php index ad52843e8473..7a8c9b946fc1 100644 --- a/Redis/tests/System/V1/CloudRedisClientTest.php +++ b/Redis/tests/System/V1/CloudRedisClientTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Redis\V1\Instance\Tier; use Google\Cloud\Redis\V1\OperationMetadata; use Google\Protobuf\GPBEmpty; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group redis @@ -37,14 +37,14 @@ class CloudRedisClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$grpcClient] ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Redis/tests/System/V1beta1/CloudRedisClientTest.php b/Redis/tests/System/V1beta1/CloudRedisClientTest.php index d7d465eeb5a5..6edadf1bfde5 100644 --- a/Redis/tests/System/V1beta1/CloudRedisClientTest.php +++ b/Redis/tests/System/V1beta1/CloudRedisClientTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Redis\V1beta1\Instance\Tier; use Google\Protobuf\Any; use Google\Protobuf\GPBEmpty; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group redis @@ -37,14 +37,14 @@ class CloudRedisClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$grpcClient] ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { # This system test fails now with the following error: # Exception: Expect utf-8 encoding. diff --git a/Redis/tests/Unit/V1/CloudRedisClientPartialVeneerTest.php b/Redis/tests/Unit/V1/CloudRedisClientPartialVeneerTest.php index cfbf8298a6b0..640e90d4ad1e 100644 --- a/Redis/tests/Unit/V1/CloudRedisClientPartialVeneerTest.php +++ b/Redis/tests/Unit/V1/CloudRedisClientPartialVeneerTest.php @@ -20,7 +20,8 @@ use Google\ApiCore\Transport\GrpcTransport; use Google\Cloud\Core\Testing\GrpcTestTrait; use Google\Cloud\Redis\V1\CloudRedisClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group redis @@ -28,18 +29,18 @@ */ class CloudRedisClientPartialVeneerTest extends TestCase { + use ExpectException; use GrpcTestTrait; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } - /** - * @expectedException InvalidArgumentException - */ public function testRestTransportFails() { + $this->expectException('InvalidArgumentException'); + new CloudRedisClient([ 'transport' => 'rest' ]); diff --git a/Redis/tests/Unit/V1beta1/CloudRedisClientPartialVeneerTest.php b/Redis/tests/Unit/V1beta1/CloudRedisClientPartialVeneerTest.php index 3eb2183d573a..f32e3741c02f 100644 --- a/Redis/tests/Unit/V1beta1/CloudRedisClientPartialVeneerTest.php +++ b/Redis/tests/Unit/V1beta1/CloudRedisClientPartialVeneerTest.php @@ -20,7 +20,8 @@ use Google\ApiCore\Transport\GrpcTransport; use Google\Cloud\Core\Testing\GrpcTestTrait; use Google\Cloud\Redis\V1beta1\CloudRedisClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group redis @@ -28,18 +29,18 @@ */ class CloudRedisClientPartialVeneerTest extends TestCase { + use ExpectException; use GrpcTestTrait; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } - /** - * @expectedException InvalidArgumentException - */ public function testRestTransportFails() { + $this->expectException('InvalidArgumentException'); + new CloudRedisClient([ 'transport' => 'rest' ]); diff --git a/ResourceManager/composer.json b/ResourceManager/composer.json index 35f9f8109a02..1a43ae2d8298 100644 --- a/ResourceManager/composer.json +++ b/ResourceManager/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ResourceSettings/composer.json b/ResourceSettings/composer.json index 6dc9e445e3e0..5411a674b27d 100644 --- a/ResourceSettings/composer.json +++ b/ResourceSettings/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Retail/composer.json b/Retail/composer.json index 0add959dbeaf..e2bd1c925a1f 100644 --- a/Retail/composer.json +++ b/Retail/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Scheduler/composer.json b/Scheduler/composer.json index 63beb8c42e0f..da3e9045a071 100644 --- a/Scheduler/composer.json +++ b/Scheduler/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Scheduler/tests/System/V1/CloudSchedulerSmokeTest.php b/Scheduler/tests/System/V1/CloudSchedulerSmokeTest.php index 1a4b74e95a02..fe706869b36a 100644 --- a/Scheduler/tests/System/V1/CloudSchedulerSmokeTest.php +++ b/Scheduler/tests/System/V1/CloudSchedulerSmokeTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Scheduler\V1\AppEngineHttpTarget; use Google\Cloud\Scheduler\V1\CloudSchedulerClient; use Google\Cloud\Scheduler\V1\Job; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group scheduler @@ -36,7 +36,7 @@ class CloudSchedulerSmokeTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$grpcClient], @@ -44,7 +44,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Scheduler/tests/System/V1beta1/CloudSchedulerSmokeTest.php b/Scheduler/tests/System/V1beta1/CloudSchedulerSmokeTest.php index 479dc2cca70b..23f982f0650a 100644 --- a/Scheduler/tests/System/V1beta1/CloudSchedulerSmokeTest.php +++ b/Scheduler/tests/System/V1beta1/CloudSchedulerSmokeTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Scheduler\V1beta1\AppEngineHttpTarget; use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient; use Google\Cloud\Scheduler\V1beta1\Job; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group scheduler @@ -36,7 +36,7 @@ class CloudSchedulerSmokeTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$grpcClient], @@ -44,7 +44,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/SecretManager/composer.json b/SecretManager/composer.json index cdc8125a0d58..838ebd5d6089 100644 --- a/SecretManager/composer.json +++ b/SecretManager/composer.json @@ -27,7 +27,8 @@ "google/gax": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/SecurityCenter/composer.json b/SecurityCenter/composer.json index 39d2f990eb31..957e555e5594 100644 --- a/SecurityCenter/composer.json +++ b/SecurityCenter/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/SecurityPrivateCa/composer.json b/SecurityPrivateCa/composer.json index bbe6cf0b64f4..64c5a40cfcab 100644 --- a/SecurityPrivateCa/composer.json +++ b/SecurityPrivateCa/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.5.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ServiceControl/composer.json b/ServiceControl/composer.json index 1eccb1a960d1..c9c5ea0af2bc 100644 --- a/ServiceControl/composer.json +++ b/ServiceControl/composer.json @@ -27,7 +27,8 @@ "google/common-protos": "^1.3.1||^2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ServiceDirectory/composer.json b/ServiceDirectory/composer.json index 2da9adcd01e9..b594e9c9bafc 100644 --- a/ServiceDirectory/composer.json +++ b/ServiceDirectory/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ServiceManagement/composer.json b/ServiceManagement/composer.json index eae561f206cc..499cfdc95a0c 100644 --- a/ServiceManagement/composer.json +++ b/ServiceManagement/composer.json @@ -27,7 +27,8 @@ "google/common-protos": "^1.3.1||^2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/ServiceUsage/composer.json b/ServiceUsage/composer.json index 86abfa5f3c8d..48961210eb2c 100644 --- a/ServiceUsage/composer.json +++ b/ServiceUsage/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Shell/composer.json b/Shell/composer.json index a03abd89e01d..f953868a7485 100644 --- a/Shell/composer.json +++ b/Shell/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Spanner/composer.json b/Spanner/composer.json index 3a8a55e15586..720a69371072 100644 --- a/Spanner/composer.json +++ b/Spanner/composer.json @@ -9,7 +9,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Spanner/phpunit-snippets.xml.dist b/Spanner/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Spanner/phpunit-snippets.xml.dist +++ b/Spanner/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Spanner/tests/Snippet/ArrayTypeTest.php b/Spanner/tests/Snippet/ArrayTypeTest.php index 24506d0f3802..c1f3d0e3d62e 100644 --- a/Spanner/tests/Snippet/ArrayTypeTest.php +++ b/Spanner/tests/Snippet/ArrayTypeTest.php @@ -50,7 +50,7 @@ class ArrayTypeTest extends SnippetTestCase private $database; private $type; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/BackupTest.php b/Spanner/tests/Snippet/BackupTest.php index 1c15bcf018be..f94d37e1008d 100644 --- a/Spanner/tests/Snippet/BackupTest.php +++ b/Spanner/tests/Snippet/BackupTest.php @@ -49,7 +49,7 @@ class BackupTest extends SnippetTestCase private $instance; private $expireTime; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -206,7 +206,7 @@ public function testState() ->WillReturn(['state' => Backup::STATE_READY]); $this->backup->___setProperty('connection', $this->connection->reveal()); - + $res = $snippet->invoke(); $this->assertEquals('Backup is ready!', $res->output()); } diff --git a/Spanner/tests/Snippet/Batch/BatchClientTest.php b/Spanner/tests/Snippet/Batch/BatchClientTest.php index 59fd40dd460c..a1635a242437 100644 --- a/Spanner/tests/Snippet/Batch/BatchClientTest.php +++ b/Spanner/tests/Snippet/Batch/BatchClientTest.php @@ -50,7 +50,7 @@ class BatchClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/Batch/BatchSnapshotTest.php b/Spanner/tests/Snippet/Batch/BatchSnapshotTest.php index 38b7a2cca52b..36ee344d4d20 100644 --- a/Spanner/tests/Snippet/Batch/BatchSnapshotTest.php +++ b/Spanner/tests/Snippet/Batch/BatchSnapshotTest.php @@ -53,7 +53,7 @@ class BatchSnapshotTest extends SnippetTestCase private $time; private $snapshot; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/Batch/QueryPartitionTest.php b/Spanner/tests/Snippet/Batch/QueryPartitionTest.php index ef97a913cd90..f81a736bca88 100644 --- a/Spanner/tests/Snippet/Batch/QueryPartitionTest.php +++ b/Spanner/tests/Snippet/Batch/QueryPartitionTest.php @@ -45,7 +45,7 @@ class QueryPartitionTest extends SnippetTestCase private $sql = 'SELECT 1=1'; private $time; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/Batch/ReadPartitionTest.php b/Spanner/tests/Snippet/Batch/ReadPartitionTest.php index eeaa6220fd1a..697c9c6046f4 100644 --- a/Spanner/tests/Snippet/Batch/ReadPartitionTest.php +++ b/Spanner/tests/Snippet/Batch/ReadPartitionTest.php @@ -50,7 +50,7 @@ class ReadPartitionTest extends SnippetTestCase private $keySet; private $columns; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/BatchDmlResultTest.php b/Spanner/tests/Snippet/BatchDmlResultTest.php index ea5ab4a9e162..8aa0a8f8accd 100644 --- a/Spanner/tests/Snippet/BatchDmlResultTest.php +++ b/Spanner/tests/Snippet/BatchDmlResultTest.php @@ -41,7 +41,7 @@ class BatchDmlResultTest extends SnippetTestCase private $result; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/BytesTest.php b/Spanner/tests/Snippet/BytesTest.php index 7539d2cf4d40..5c73e3c8f0b6 100644 --- a/Spanner/tests/Snippet/BytesTest.php +++ b/Spanner/tests/Snippet/BytesTest.php @@ -34,7 +34,7 @@ class BytesTest extends SnippetTestCase private $bytes; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); $this->bytes = new Bytes(self::BYTES); diff --git a/Spanner/tests/Snippet/CommitTimestampTest.php b/Spanner/tests/Snippet/CommitTimestampTest.php index 0a812be77289..18e15c0904a4 100644 --- a/Spanner/tests/Snippet/CommitTimestampTest.php +++ b/Spanner/tests/Snippet/CommitTimestampTest.php @@ -37,7 +37,7 @@ class CommitTimestampTest extends SnippetTestCase const SESSION = 'projects/my-awesome-project/instances/my-instance/databases/my-database/sessions/session-id'; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } diff --git a/Spanner/tests/Snippet/DatabaseTest.php b/Spanner/tests/Snippet/DatabaseTest.php index c027299be317..484b09e9bc7f 100644 --- a/Spanner/tests/Snippet/DatabaseTest.php +++ b/Spanner/tests/Snippet/DatabaseTest.php @@ -63,7 +63,7 @@ class DatabaseTest extends SnippetTestCase private $database; private $instance; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -138,7 +138,7 @@ public function testState() ->WillReturn(['state' => Database::STATE_READY]); $this->database->___setProperty('connection', $this->connection->reveal()); - + $res = $snippet->invoke(); $this->assertEquals('Database is ready!', $res->output()); } @@ -283,7 +283,7 @@ public function testRestore() $snippet = $this->snippetFromMethod(Database::class, 'restore'); $snippet->addLocal('database', $this->database); $snippet->addLocal('backup', $backup); - + $this->connection->restoreDatabase(Argument::any()) ->shouldBeCalled() ->willReturn([ diff --git a/Spanner/tests/Snippet/DateTest.php b/Spanner/tests/Snippet/DateTest.php index 85aa01970655..7e25c46c5439 100644 --- a/Spanner/tests/Snippet/DateTest.php +++ b/Spanner/tests/Snippet/DateTest.php @@ -32,7 +32,7 @@ class DateTest extends SnippetTestCase private $dt; private $date; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/DurationTest.php b/Spanner/tests/Snippet/DurationTest.php index a3c68d323d4d..1b2bdc79c8f4 100644 --- a/Spanner/tests/Snippet/DurationTest.php +++ b/Spanner/tests/Snippet/DurationTest.php @@ -33,7 +33,7 @@ class DurationTest extends SnippetTestCase private $duration; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/InstanceConfigurationTest.php b/Spanner/tests/Snippet/InstanceConfigurationTest.php index ad4bdb39df6d..d9f8e444d6d2 100644 --- a/Spanner/tests/Snippet/InstanceConfigurationTest.php +++ b/Spanner/tests/Snippet/InstanceConfigurationTest.php @@ -40,7 +40,7 @@ class InstanceConfigurationTest extends SnippetTestCase private $connection; private $config; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/InstanceTest.php b/Spanner/tests/Snippet/InstanceTest.php index 156516d4e548..1c6eb5c9bbfe 100644 --- a/Spanner/tests/Snippet/InstanceTest.php +++ b/Spanner/tests/Snippet/InstanceTest.php @@ -52,7 +52,7 @@ class InstanceTest extends SnippetTestCase private $connection; private $instance; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -290,7 +290,7 @@ public function testBackups() ] ] ]); - + $this->instance->___setProperty('connection', $this->connection->reveal()); $res = $snippet->invoke('backups'); @@ -348,7 +348,7 @@ public function testDatabaseOperations() ] ] ]); - + $this->instance->___setProperty('connection', $this->connection->reveal()); $res = $snippet->invoke('databaseOperations'); diff --git a/Spanner/tests/Snippet/KeyRangeTest.php b/Spanner/tests/Snippet/KeyRangeTest.php index d8822a175016..0aac11756bf4 100644 --- a/Spanner/tests/Snippet/KeyRangeTest.php +++ b/Spanner/tests/Snippet/KeyRangeTest.php @@ -30,7 +30,7 @@ class KeyRangeTest extends SnippetTestCase private $range; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/KeySetTest.php b/Spanner/tests/Snippet/KeySetTest.php index b365d8b27bae..f2c451b0d2f4 100644 --- a/Spanner/tests/Snippet/KeySetTest.php +++ b/Spanner/tests/Snippet/KeySetTest.php @@ -32,7 +32,7 @@ class KeySetTest extends SnippetTestCase private $keyset; private $range; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/ResultTest.php b/Spanner/tests/Snippet/ResultTest.php index 12c8c547c197..76d1cd34e273 100644 --- a/Spanner/tests/Snippet/ResultTest.php +++ b/Spanner/tests/Snippet/ResultTest.php @@ -25,18 +25,20 @@ use Google\Cloud\Spanner\Transaction; use Google\Cloud\Core\Testing\GrpcTestTrait; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group spanner */ class ResultTest extends SnippetTestCase { + use AssertIsType; use GrpcTestTrait; private $database; private $result; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -84,7 +86,7 @@ public function testColumns() $snippet = $this->snippetFromMethod(Result::class, 'columns'); $snippet->addLocal('result', $this->result); $res = $snippet->invoke('columns'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } public function testMetadata() @@ -92,7 +94,7 @@ public function testMetadata() $snippet = $this->snippetFromMethod(Result::class, 'metadata'); $snippet->addLocal('result', $this->result); $res = $snippet->invoke('metadata'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } public function testSession() @@ -108,7 +110,7 @@ public function testStats() $snippet = $this->snippetFromMethod(Result::class, 'stats'); $snippet->addLocal('result', $this->result); $res = $snippet->invoke('stats'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } public function testQueryWithStats() diff --git a/Spanner/tests/Snippet/SnapshotTest.php b/Spanner/tests/Snippet/SnapshotTest.php index 5b6b96aaedb7..d529e2280728 100644 --- a/Spanner/tests/Snippet/SnapshotTest.php +++ b/Spanner/tests/Snippet/SnapshotTest.php @@ -42,7 +42,7 @@ class SnapshotTest extends SnippetTestCase private $connection; private $snapshot; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/SpannerClientTest.php b/Spanner/tests/Snippet/SpannerClientTest.php index da0d80549286..0bd62767c2dc 100644 --- a/Spanner/tests/Snippet/SpannerClientTest.php +++ b/Spanner/tests/Snippet/SpannerClientTest.php @@ -56,7 +56,7 @@ class SpannerClientTest extends SnippetTestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/StructTypeTest.php b/Spanner/tests/Snippet/StructTypeTest.php index 62803dce0a7f..7791b9e031f8 100644 --- a/Spanner/tests/Snippet/StructTypeTest.php +++ b/Spanner/tests/Snippet/StructTypeTest.php @@ -50,7 +50,7 @@ class StructTypeTest extends SnippetTestCase private $database; private $type; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/StructValueTest.php b/Spanner/tests/Snippet/StructValueTest.php index 2ecb78a04021..ea3d0db9b80e 100644 --- a/Spanner/tests/Snippet/StructValueTest.php +++ b/Spanner/tests/Snippet/StructValueTest.php @@ -49,7 +49,7 @@ class StructValueTest extends SnippetTestCase private $database; private $value; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/TimestampTest.php b/Spanner/tests/Snippet/TimestampTest.php index 02c1bc2806b5..11bf4ea9882a 100644 --- a/Spanner/tests/Snippet/TimestampTest.php +++ b/Spanner/tests/Snippet/TimestampTest.php @@ -31,7 +31,7 @@ class TimestampTest extends SnippetTestCase private $timestamp; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/TransactionTest.php b/Spanner/tests/Snippet/TransactionTest.php index 3bb6d3844d05..bc638a50a62c 100644 --- a/Spanner/tests/Snippet/TransactionTest.php +++ b/Spanner/tests/Snippet/TransactionTest.php @@ -50,7 +50,7 @@ class TransactionTest extends SnippetTestCase private $connection; private $transaction; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Snippet/TransactionalReadMethodsTest.php b/Spanner/tests/Snippet/TransactionalReadMethodsTest.php index 84d4fe2301b5..9aa11e2e107f 100644 --- a/Spanner/tests/Snippet/TransactionalReadMethodsTest.php +++ b/Spanner/tests/Snippet/TransactionalReadMethodsTest.php @@ -65,9 +65,9 @@ class TransactionalReadMethodsTest extends SnippetTestCase private $transaction; private $snapshot; - public function setUp() + public function set_up() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $this->connection = $this->getConnStub(); $this->session = $this->prophesize(Session::class); diff --git a/Spanner/tests/StubCreationTrait.php b/Spanner/tests/StubCreationTrait.php index 825f9f5e0053..3fb24fbd736f 100644 --- a/Spanner/tests/StubCreationTrait.php +++ b/Spanner/tests/StubCreationTrait.php @@ -32,6 +32,4 @@ private function getConnStub() return $c; } - - abstract protected function prophesize($classOrInterface = null); } diff --git a/Spanner/tests/System/BackupTest.php b/Spanner/tests/System/BackupTest.php index c31d600e7070..055a4f1cf885 100644 --- a/Spanner/tests/System/BackupTest.php +++ b/Spanner/tests/System/BackupTest.php @@ -28,12 +28,15 @@ use Google\Cloud\Spanner\Admin\Database\V1\EncryptionInfo\Type; use Google\Cloud\Spanner\Backup; use Google\Cloud\Spanner\Date; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class BackupTest extends SpannerTestCase { + use ExpectException; + const BACKUP_PREFIX = 'spanner_backup_'; protected static $backupId1; @@ -52,11 +55,11 @@ class BackupTest extends SpannerTestCase private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::set_up_before_class(); if (self::$hasSetUp) { return; } diff --git a/Spanner/tests/System/BatchTest.php b/Spanner/tests/System/BatchTest.php index 5ff30125d8aa..7f5438805fc0 100644 --- a/Spanner/tests/System/BatchTest.php +++ b/Spanner/tests/System/BatchTest.php @@ -30,9 +30,9 @@ class BatchTest extends SpannerTestCase { private static $tableName; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); self::$tableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/LargeReadTest.php b/Spanner/tests/System/LargeReadTest.php index f40e7174fedc..6e81548ce74e 100644 --- a/Spanner/tests/System/LargeReadTest.php +++ b/Spanner/tests/System/LargeReadTest.php @@ -38,9 +38,9 @@ class LargeReadTest extends SpannerTestCase private static $str = ''; const NUM = 40000; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); self::$tableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/OperationsTest.php b/Spanner/tests/System/OperationsTest.php index fa27112f107c..7fbb7aabce30 100644 --- a/Spanner/tests/System/OperationsTest.php +++ b/Spanner/tests/System/OperationsTest.php @@ -30,14 +30,14 @@ class OperationsTest extends SpannerTestCase private static $name1; private static $name2; - public static function setUpBeforeClass() + public static function set_up_before_class() { self::$id1 = rand(1000, 9999); self::$id2 = rand(1, 999); self::$name1 = uniqid(self::TESTING_PREFIX); self::$name2 = uniqid(self::TESTING_PREFIX); - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$database->insert(self::TEST_TABLE_NAME, [ 'id' => self::$id1, diff --git a/Spanner/tests/System/PgQueryTest.php b/Spanner/tests/System/PgQueryTest.php index cefec12dcbaf..01d5d05ede38 100644 --- a/Spanner/tests/System/PgQueryTest.php +++ b/Spanner/tests/System/PgQueryTest.php @@ -26,6 +26,7 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Transaction; use Google\Cloud\Spanner\V1\RequestOptions\Priority; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -34,14 +35,15 @@ */ class PgQueryTest extends SpannerPgTestCase { + use ExpectException; const TABLE_NAME = 'test'; public static $timestampVal; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$database->updateDdl( 'CREATE TABLE ' . self::TABLE_NAME . ' ( @@ -106,11 +108,10 @@ public function testSelect1WithRequestOptions() $this->assertEquals(1, $row['foo']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testInvalidQueryFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $db = self::$database; $db->execute('badquery')->rows()->current(); diff --git a/Spanner/tests/System/PgReadTest.php b/Spanner/tests/System/PgReadTest.php index 7ec614a2696d..bd71a9e6cc82 100644 --- a/Spanner/tests/System/PgReadTest.php +++ b/Spanner/tests/System/PgReadTest.php @@ -19,6 +19,8 @@ use Google\Cloud\Spanner\KeyRange; use Google\Cloud\Spanner\KeySet; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -27,14 +29,17 @@ */ class PgReadTest extends SpannerPgTestCase { + use AssertStringContains; + use ExpectException; + private static $readTableName; private static $rangeTableName; private static $indexes = []; private static $dataset; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); self::$readTableName = "read_table"; self::$rangeTableName = "range_table"; @@ -80,8 +85,8 @@ public function testRangeReadSingleKeyOpen() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadSingleKeyClosed() @@ -99,8 +104,8 @@ public function testRangeReadSingleKeyClosed() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testRangeReadSingleKeyOpenClosed() @@ -117,8 +122,8 @@ public function testRangeReadSingleKeyOpenClosed() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testRangeReadSingleKeyClosedOpen() @@ -135,8 +140,8 @@ public function testRangeReadSingleKeyClosedOpen() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadPartialKeyOpen() @@ -152,8 +157,8 @@ public function testRangeReadPartialKeyOpen() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadPartialKeyClosed() @@ -171,8 +176,8 @@ public function testRangeReadPartialKeyClosed() $res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0])); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexSingleKeyOpen() @@ -190,8 +195,8 @@ public function testRangeReadIndexSingleKeyOpen() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexSingleKeyClosed() @@ -211,8 +216,8 @@ public function testRangeReadIndexSingleKeyClosed() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexSingleKeyOpenClosed() @@ -231,8 +236,8 @@ public function testRangeReadIndexSingleKeyOpenClosed() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexSingleKeyClosedOpen() @@ -251,8 +256,8 @@ public function testRangeReadIndexSingleKeyClosedOpen() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexPartialKeyOpen() @@ -270,8 +275,8 @@ public function testRangeReadIndexPartialKeyOpen() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertNotContains(self::$dataset[0], $rows); - $this->assertNotContains(self::$dataset[10], $rows); + $this->assertStringNotContainsString(self::$dataset[0], $rows); + $this->assertStringNotContainsString(self::$dataset[10], $rows); } public function testRangeReadIndexPartialKeyClosed() @@ -291,8 +296,8 @@ public function testRangeReadIndexPartialKeyClosed() 'index' => $this->getIndexName(self::$rangeTableName, 'complex') ]); $rows = iterator_to_array($res->rows()); - $this->assertContains(self::$dataset[0], $rows); - $this->assertContains(self::$dataset[10], $rows); + $this->assertStringContainsString(self::$dataset[0], $rows); + $this->assertStringContainsString(self::$dataset[10], $rows); } public function testReadWithLimit() @@ -352,8 +357,8 @@ public function testReadPoint() $res = $db->read(self::$readTableName, $keyset, array_keys($dataset[0])); $rows = $res->rows(); foreach ($rows as $index => $row) { - $this->assertContains($row, $dataset); - $this->assertContains($row, $points); + $this->assertStringContainsString($row, $dataset); + $this->assertStringContainsString($row, $points); } } @@ -379,49 +384,45 @@ public function testReadPointOverIndex() ]); $rows = $res->rows(); foreach ($rows as $index => $row) { - $this->assertContains($row, $dataset); - $this->assertContains($row, $points); + $this->assertStringContainsString($row, $dataset); + $this->assertStringContainsString($row, $points); } } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testReadInvalidDatabase() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$client->connect('google-cloud-php-system-tests', uniqid(self::TESTING_PREFIX)); $keyset = new KeySet(['all' => true]); $db->read(self::TEST_TABLE_NAME, $keyset, [])->rows()->current(); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testReadInvalidTable() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $keyset = new KeySet(['all' => true]); $db->read('ThisIsntARealTable', $keyset, ['id'])->rows()->current(); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testReadInvalidColumn() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $keyset = new KeySet(['all' => true]); $db->read(self::TEST_TABLE_NAME, $keyset, [uniqid('id')])->rows()->current(); } - /** - * @expectedException Google\Cloud\Core\Exception\DeadlineExceededException - */ public function testReadFailsOnDeadlineExceeded() { + $this->expectException('Google\Cloud\Core\Exception\DeadlineExceededException'); + $this->skipEmulatorTests(); $db = self::$database; $keyset = new KeySet(['all' => true]); diff --git a/Spanner/tests/System/PgTransactionTest.php b/Spanner/tests/System/PgTransactionTest.php index 289be2c5eebd..bf3f19c9cb05 100644 --- a/Spanner/tests/System/PgTransactionTest.php +++ b/Spanner/tests/System/PgTransactionTest.php @@ -33,9 +33,9 @@ class PgTransactionTest extends SpannerPgTestCase private static $tableName; private static $table2; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$tableName = "transactions_test"; self::$table2 = "transactions_users"; diff --git a/Spanner/tests/System/PgWriteTest.php b/Spanner/tests/System/PgWriteTest.php index c3d5d2828f83..b970b59ccc4a 100644 --- a/Spanner/tests/System/PgWriteTest.php +++ b/Spanner/tests/System/PgWriteTest.php @@ -25,6 +25,7 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\PgNumeric; use Google\Rpc\Code; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -33,14 +34,15 @@ */ class PgWriteTest extends SpannerPgTestCase { + use ExpectException; use TimeTrait; const TABLE_NAME = 'Writes'; const COMMIT_TIMESTAMP_TABLE_NAME = 'CommitTimestamps'; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$database->updateDdlBatch([ 'CREATE TABLE ' . self::TABLE_NAME . ' ( @@ -329,31 +331,28 @@ public function testWriteAndReadBackArrayComplexValue($id, $field, $value) } } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testWriteToNonExistentTableFails() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $db->insert(uniqid(self::TESTING_PREFIX), ['foo' => 'bar']); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testWriteToNonExistentColumnFails() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $db->insert(self::TABLE_NAME, [uniqid(self::TESTING_PREFIX) => 'bar']); } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testWriteIncorrectTypeToColumn() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $db = self::$database; $db->insert(self::TABLE_NAME, [ @@ -886,10 +885,11 @@ public function testExecuteUpdateBatchSingleStatement() * an empty result list. * * @group spanner-write-batch-dml - * @expectedException Google\Cloud\Core\Exception\BadRequestException */ public function testExecuteUpdateBatchNoStatementsThrowsException() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $db = self::$database; $res = $db->runTransaction(function ($t) { $res = $t->executeUpdateBatch([]); diff --git a/Spanner/tests/System/QueryTest.php b/Spanner/tests/System/QueryTest.php index 835cc9c2849a..040cfe5424cf 100644 --- a/Spanner/tests/System/QueryTest.php +++ b/Spanner/tests/System/QueryTest.php @@ -28,6 +28,7 @@ use Google\Cloud\Spanner\StructValue; use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\V1\RequestOptions\Priority; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -35,6 +36,8 @@ */ class QueryTest extends SpannerTestCase { + use ExpectException; + /** * covers 19 */ @@ -64,10 +67,11 @@ public function testSelect1WithRequestOptions() /** * covers 20 - * @expectedException Google\Cloud\Core\Exception\BadRequestException */ public function testInvalidQueryFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $db = self::$database; $db->execute('badquery')->rows()->current(); diff --git a/Spanner/tests/System/ReadTest.php b/Spanner/tests/System/ReadTest.php index a7e383f146df..437dd2615579 100644 --- a/Spanner/tests/System/ReadTest.php +++ b/Spanner/tests/System/ReadTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Spanner\KeyRange; use Google\Cloud\Spanner\KeySet; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -26,14 +27,16 @@ */ class ReadTest extends SpannerTestCase { + use ExpectException; + private static $readTableName; private static $rangeTableName; private static $indexes = []; private static $dataset; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); self::$readTableName = uniqid(self::TESTING_PREFIX); self::$rangeTableName = uniqid(self::TESTING_PREFIX); @@ -432,10 +435,11 @@ public function testReadPointOverIndex() /** * covers 14 - * @expectedException Google\Cloud\Core\Exception\NotFoundException */ public function testReadInvalidDatabase() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$client->connect('google-cloud-php-system-tests', uniqid(self::TESTING_PREFIX)); $keyset = new KeySet(['all' => true]); @@ -444,10 +448,11 @@ public function testReadInvalidDatabase() /** * covers 15 - * @expectedException Google\Cloud\Core\Exception\NotFoundException */ public function testReadInvalidTable() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $keyset = new KeySet(['all' => true]); @@ -456,10 +461,11 @@ public function testReadInvalidTable() /** * covers 16 - * @expectedException Google\Cloud\Core\Exception\NotFoundException */ public function testReadInvalidColumn() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $keyset = new KeySet(['all' => true]); @@ -468,10 +474,11 @@ public function testReadInvalidColumn() /** * covers 18 - * @expectedException Google\Cloud\Core\Exception\DeadlineExceededException */ public function testReadFailsOnDeadlineExceeded() { + $this->expectException('Google\Cloud\Core\Exception\DeadlineExceededException'); + $this->skipEmulatorTests(); $db = self::$database; $keyset = new KeySet(['all' => true]); diff --git a/Spanner/tests/System/SnapshotTest.php b/Spanner/tests/System/SnapshotTest.php index 68550879389b..d3e6f69943df 100644 --- a/Spanner/tests/System/SnapshotTest.php +++ b/Spanner/tests/System/SnapshotTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Spanner\Duration; use Google\Cloud\Spanner\Timestamp; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -26,13 +27,15 @@ */ class SnapshotTest extends SpannerTestCase { + use ExpectException; + const TABLE_NAME = 'Snapshots'; private static $tableName; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$tableName = uniqid(self::TABLE_NAME); @@ -208,10 +211,11 @@ public function testSnapshotMaxStaleness() /** * covers 71 - * @expectedException \BadMethodCallException */ public function testSnapshotMinReadTimestampFails() { + $this->expectException('\BadMethodCallException'); + $db = self::$database; $db->snapshot([ @@ -221,10 +225,11 @@ public function testSnapshotMinReadTimestampFails() /** * covers 72 - * @expectedException \BadMethodCallException */ public function testSnapshotMaxStalenessFails() { + $this->expectException('\BadMethodCallException'); + $db = self::$database; $db->snapshot([ diff --git a/Spanner/tests/System/SpannerPgTestCase.php b/Spanner/tests/System/SpannerPgTestCase.php index a80af2a4f09a..bcc48a3a1791 100644 --- a/Spanner/tests/System/SpannerPgTestCase.php +++ b/Spanner/tests/System/SpannerPgTestCase.php @@ -42,7 +42,7 @@ class SpannerPgTestCase extends SystemTestCase private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Spanner/tests/System/SpannerTestCase.php b/Spanner/tests/System/SpannerTestCase.php index 0931f4016902..58bd609aa23b 100644 --- a/Spanner/tests/System/SpannerTestCase.php +++ b/Spanner/tests/System/SpannerTestCase.php @@ -40,7 +40,7 @@ class SpannerTestCase extends SystemTestCase private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Spanner/tests/System/TransactionTest.php b/Spanner/tests/System/TransactionTest.php index c7dd15717511..bbef6f9006ce 100644 --- a/Spanner/tests/System/TransactionTest.php +++ b/Spanner/tests/System/TransactionTest.php @@ -33,9 +33,9 @@ class TransactionTest extends SpannerTestCase private static $tableName; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$tableName = uniqid(self::TABLE_NAME); diff --git a/Spanner/tests/System/WriteTest.php b/Spanner/tests/System/WriteTest.php index 936e206b5a99..3823214f684c 100644 --- a/Spanner/tests/System/WriteTest.php +++ b/Spanner/tests/System/WriteTest.php @@ -25,6 +25,7 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Numeric; use Google\Rpc\Code; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -32,15 +33,16 @@ */ class WriteTest extends SpannerTestCase { + use ExpectException; use TimeTrait; const TABLE_NAME = 'Writes'; const COMMIT_TIMESTAMP_TABLE_NAME = 'CommitTimestamps'; - public static function setupBeforeClass() + public static function set_up_before_class() { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$database->updateDdlBatch([ 'CREATE TABLE ' . self::TABLE_NAME . ' ( @@ -370,31 +372,28 @@ public function testWriteAndReadBackFancyArrayComplexValue($id, $field, $value) } } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testWriteToNonExistentTableFails() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $db->insert(uniqid(self::TESTING_PREFIX), ['foo' => 'bar']); } - /** - * @expectedException Google\Cloud\Core\Exception\NotFoundException - */ public function testWriteToNonExistentColumnFails() { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $db = self::$database; $db->insert(self::TABLE_NAME, [uniqid(self::TESTING_PREFIX) => 'bar']); } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testWriteIncorrectTypeToColumn() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $db = self::$database; $db->insert(self::TABLE_NAME, [ @@ -925,10 +924,11 @@ public function testExecuteUpdateBatchSingleStatement() * an empty result list. * * @group spanner-write-batch-dml - * @expectedException Google\Cloud\Core\Exception\BadRequestException */ public function testExecuteUpdateBatchNoStatementsThrowsException() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $db = self::$database; $res = $db->runTransaction(function ($t) { $res = $t->executeUpdateBatch([]); diff --git a/Spanner/tests/Unit/ArrayTypeTest.php b/Spanner/tests/Unit/ArrayTypeTest.php index b8980ef391c4..af87b9f3578a 100644 --- a/Spanner/tests/Unit/ArrayTypeTest.php +++ b/Spanner/tests/Unit/ArrayTypeTest.php @@ -21,6 +21,7 @@ use Google\Cloud\Spanner\Database; use Google\Cloud\Spanner\StructType; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -28,6 +29,8 @@ */ class ArrayTypeTest extends TestCase { + use ExpectException; + public function typesProvider() { return [ @@ -78,10 +81,11 @@ public function testArrayTypeStruct() /** * @dataProvider invalidTypeProvider - * @expectedException \InvalidArgumentException */ public function testFailsOnInvalidType($type) { + $this->expectException('\InvalidArgumentException'); + new ArrayType($type); } } diff --git a/Spanner/tests/Unit/BackupTest.php b/Spanner/tests/Unit/BackupTest.php index 05fb9c31d201..59d2211d9f10 100644 --- a/Spanner/tests/Unit/BackupTest.php +++ b/Spanner/tests/Unit/BackupTest.php @@ -33,7 +33,7 @@ use Google\Cloud\Spanner\Database; use Google\Cloud\Spanner\Instance; use Google\Cloud\Spanner\Timestamp; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -61,7 +61,7 @@ class BackupTest extends TestCase private $backup; private $copiedBackup; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -91,7 +91,7 @@ public function setUp() 'instance', 'connection' ]; $this->backup = TestHelpers::stub(Backup::class, $args, $props); - + // copiedBackup will contain a mock of the backup object where // $backup will be copied into $copyArgs = $args; diff --git a/Spanner/tests/Unit/Batch/BatchClientTest.php b/Spanner/tests/Unit/Batch/BatchClientTest.php index 3584cc92cb23..ebab62b35ae3 100644 --- a/Spanner/tests/Unit/Batch/BatchClientTest.php +++ b/Spanner/tests/Unit/Batch/BatchClientTest.php @@ -27,9 +27,10 @@ use Google\Cloud\Spanner\KeySet; use Google\Cloud\Spanner\Operation; use Google\Cloud\Spanner\Tests\OperationRefreshTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Google\Cloud\Spanner\Tests\StubCreationTrait; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -38,6 +39,7 @@ */ class BatchClientTest extends TestCase { + use ExpectException; use OperationRefreshTrait; use StubCreationTrait; use TimeTrait; @@ -49,7 +51,7 @@ class BatchClientTest extends TestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->getConnStub(); $this->client = TestHelpers::stub(BatchClient::class, [ @@ -143,22 +145,20 @@ public function testReadPartitionFromString() $this->assertEquals($options, $res->options()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid partition data. - */ public function testMissingPartitionTypeKey() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid partition data.'); + $data = base64_encode(json_encode(['hello' => 'world'])); $this->client->partitionFromString($data); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid partition type. - */ public function testInvalidPartitionType() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid partition type.'); + $data = base64_encode(json_encode([BatchClient::PARTITION_TYPE_KEY => uniqid('this-is-not-real')])); $this->client->partitionFromString($data); } diff --git a/Spanner/tests/Unit/Batch/BatchSnapshotTest.php b/Spanner/tests/Unit/Batch/BatchSnapshotTest.php index fe43ac3359ef..1f2c37674a23 100644 --- a/Spanner/tests/Unit/Batch/BatchSnapshotTest.php +++ b/Spanner/tests/Unit/Batch/BatchSnapshotTest.php @@ -31,8 +31,9 @@ use Google\Cloud\Spanner\Tests\StubCreationTrait; use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\V1\SpannerClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -41,6 +42,7 @@ */ class BatchSnapshotTest extends TestCase { + use ExpectException; use OperationRefreshTrait; use ResultGeneratorTrait; use StubCreationTrait; @@ -54,7 +56,7 @@ class BatchSnapshotTest extends TestCase private $connection; private $snapshot; - public function setUp() + public function set_up() { $sessData = SpannerClient::parseName(self::SESSION, 'session'); $this->session = $this->prophesize(Session::class); @@ -244,12 +246,11 @@ public function testSerialize() $this->assertEquals($identifier, (string) $this->snapshot); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage Unsupported partition type. - */ public function testExecutePartitionInvalidType() { + $this->expectException('BadMethodCallException'); + $this->expectExceptionMessage('Unsupported partition type.'); + $dummy = new DummyPartition; $this->snapshot->executePartition($dummy); } diff --git a/Spanner/tests/Unit/BytesTest.php b/Spanner/tests/Unit/BytesTest.php index e9616a0c3875..e7a7ecb2baf2 100644 --- a/Spanner/tests/Unit/BytesTest.php +++ b/Spanner/tests/Unit/BytesTest.php @@ -19,18 +19,20 @@ use Google\Cloud\Spanner\Bytes; use Google\Cloud\Core\Testing\GrpcTestTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group spanner */ class BytesTest extends TestCase { + use AssertIsType; use GrpcTestTrait; private $content = 'hello'; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } @@ -56,6 +58,6 @@ public function testCast() public function testType() { $bytes = new Bytes($this->content); - $this->assertInternalType('int', $bytes->type()); + $this->assertIsInt($bytes->type()); } } diff --git a/Spanner/tests/Unit/CommitTimestampTest.php b/Spanner/tests/Unit/CommitTimestampTest.php index 3a7062c663b5..d0a3e01bc8aa 100644 --- a/Spanner/tests/Unit/CommitTimestampTest.php +++ b/Spanner/tests/Unit/CommitTimestampTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Spanner\CommitTimestamp; use Google\Cloud\Spanner\Database; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner @@ -28,7 +28,7 @@ class CommitTimestampTest extends TestCase { private $t; - public function setUp() + public function set_up() { $this->t = new CommitTimestamp; } diff --git a/Spanner/tests/Unit/Connection/GrpcTest.php b/Spanner/tests/Unit/Connection/GrpcTest.php index e6faa0b37a12..3d0f0b8818bb 100644 --- a/Spanner/tests/Unit/Connection/GrpcTest.php +++ b/Spanner/tests/Unit/Connection/GrpcTest.php @@ -57,7 +57,7 @@ use Google\Protobuf\Value; use GuzzleHttp\Promise\PromiseInterface; use http\Exception\InvalidArgumentException; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -82,7 +82,7 @@ class GrpcTest extends TestCase private $successMessage; private $lro; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Unit/Connection/IamDatabaseTest.php b/Spanner/tests/Unit/Connection/IamDatabaseTest.php index 008905fbd932..4ec54d416690 100644 --- a/Spanner/tests/Unit/Connection/IamDatabaseTest.php +++ b/Spanner/tests/Unit/Connection/IamDatabaseTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Spanner\Connection\IamDatabase; use Google\Cloud\Spanner\Tests\StubCreationTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner-admin @@ -34,7 +34,7 @@ class IamDatabaseTest extends TestCase private $iam; - public function setUp() + public function set_up() { $this->connection = $this->getConnStub(); diff --git a/Spanner/tests/Unit/Connection/IamInstanceTest.php b/Spanner/tests/Unit/Connection/IamInstanceTest.php index 6d27526323cb..5ebfb3a56dc3 100644 --- a/Spanner/tests/Unit/Connection/IamInstanceTest.php +++ b/Spanner/tests/Unit/Connection/IamInstanceTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Spanner\Connection\IamInstance; use Google\Cloud\Spanner\Tests\StubCreationTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner-admin @@ -34,7 +34,7 @@ class IamInstanceTest extends TestCase private $iam; - public function setUp() + public function set_up() { $this->connection = $this->getConnStub(); diff --git a/Spanner/tests/Unit/Connection/LongRunningConnectionTest.php b/Spanner/tests/Unit/Connection/LongRunningConnectionTest.php index f8a75b580ed3..6bcac80ab824 100644 --- a/Spanner/tests/Unit/Connection/LongRunningConnectionTest.php +++ b/Spanner/tests/Unit/Connection/LongRunningConnectionTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Spanner\Connection\LongRunningConnection; use Google\Cloud\Spanner\Tests\StubCreationTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner @@ -33,7 +33,7 @@ class LongRunningConnectionTest extends TestCase private $connection; private $lro; - public function setUp() + public function set_up() { $this->connection = $this->getConnStub(); $this->lro = TestHelpers::stub(LongRunningConnection::class, [ diff --git a/Spanner/tests/Unit/DatabaseTest.php b/Spanner/tests/Unit/DatabaseTest.php index 1fc5ccb02445..662ce39b9161 100644 --- a/Spanner/tests/Unit/DatabaseTest.php +++ b/Spanner/tests/Unit/DatabaseTest.php @@ -46,8 +46,9 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Transaction; use Google\Cloud\Spanner\V1\SpannerClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -55,6 +56,7 @@ */ class DatabaseTest extends TestCase { + use ExpectException; use GrpcTestTrait; use OperationRefreshTrait; use ResultGeneratorTrait; @@ -77,7 +79,7 @@ class DatabaseTest extends TestCase private $session; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -582,27 +584,24 @@ public function testSnapshot() $this->assertInstanceOf(Snapshot::class, $res); } - /** - * @expectedException BadMethodCallException - */ public function testSnapshotMinReadTimestamp() { + $this->expectException('BadMethodCallException'); + $this->database->snapshot(['minReadTimestamp' => 'foo']); } - /** - * @expectedException BadMethodCallException - */ public function testSnapshotMaxStaleness() { + $this->expectException('BadMethodCallException'); + $this->database->snapshot(['maxStaleness' => 'foo']); } - /** - * @expectedException BadMethodCallException - */ public function testSnapshotNestedTransaction() { + $this->expectException('BadMethodCallException'); + $this->connection->beginTransaction(Argument::allOf( Argument::withEntry('session', $this->session->name()), Argument::withEntry( @@ -676,11 +675,10 @@ public function testRunTransaction() $this->assertTrue($hasTransaction); } - /** - * @expectedException RuntimeException - */ public function testRunTransactionNoCommit() { + $this->expectException('RuntimeException'); + $this->connection->beginTransaction(Argument::allOf( Argument::withEntry('session', $this->session->name()), Argument::withEntry( @@ -713,11 +711,10 @@ public function testRunTransactionNoCommit() $this->database->runTransaction($this->noop()); } - /** - * @expectedException BadMethodCallException - */ public function testRunTransactionNestedTransaction() { + $this->expectException('BadMethodCallException'); + $this->connection->beginTransaction(Argument::allOf( Argument::withEntry('session', $this->session->name()), Argument::withEntry( @@ -802,11 +799,10 @@ public function testRunTransactionRetry() }); } - /** - * @expectedException Google\Cloud\Core\Exception\AbortedException - */ public function testRunTransactionAborted() { + $this->expectException('Google\Cloud\Core\Exception\AbortedException'); + $abort = new AbortedException('foo', 409, null, [ [ 'retryDelay' => [ @@ -885,11 +881,10 @@ public function testTransaction() $this->assertInstanceOf(Transaction::class, $t); } - /** - * @expectedException BadMethodCallException - */ public function testTransactionNestedTransaction() { + $this->expectException('BadMethodCallException'); + $this->connection->beginTransaction(Argument::allOf( Argument::withEntry('session', $this->session->name()), Argument::withEntry( @@ -1217,11 +1212,10 @@ public function testExecuteSingleUseMaxStaleness() $rows = iterator_to_array($res->rows()); } - /** - * @expectedException BadMethodCallException - */ public function testExecuteBeginMaxStalenessFails() { + $this->expectException('BadMethodCallException'); + $this->database->___setProperty('sessionPool', null); $this->database->___setProperty('session', $this->session); $sql = 'SELECT * FROM Table'; diff --git a/Spanner/tests/Unit/DateTest.php b/Spanner/tests/Unit/DateTest.php index 0c8ede028c4a..3f5c73cb1f11 100644 --- a/Spanner/tests/Unit/DateTest.php +++ b/Spanner/tests/Unit/DateTest.php @@ -19,19 +19,21 @@ use Google\Cloud\Spanner\Date; use Google\Cloud\Core\Testing\GrpcTestTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group spanner */ class DateTest extends TestCase { + use AssertIsType; use GrpcTestTrait; private $dt; private $date; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -62,6 +64,6 @@ public function testCast() public function testType() { - $this->assertInternalType('int', $this->date->type()); + $this->assertIsInt($this->date->type()); } } diff --git a/Spanner/tests/Unit/DurationTest.php b/Spanner/tests/Unit/DurationTest.php index 5dd61d7cac8f..be9223ae7403 100644 --- a/Spanner/tests/Unit/DurationTest.php +++ b/Spanner/tests/Unit/DurationTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Spanner\Tests\Unit; use Google\Cloud\Spanner\Duration; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner @@ -30,7 +30,7 @@ class DurationTest extends TestCase private $duration; - public function setUp() + public function set_up() { $this->duration = new Duration(self::SECONDS, self::NANOS); } diff --git a/Spanner/tests/Unit/GapicBackoff/GapicBackoffTest.php b/Spanner/tests/Unit/GapicBackoff/GapicBackoffTest.php index c00c9afc3b2e..f9fbc7d424ce 100644 --- a/Spanner/tests/Unit/GapicBackoff/GapicBackoffTest.php +++ b/Spanner/tests/Unit/GapicBackoff/GapicBackoffTest.php @@ -17,7 +17,7 @@ namespace Google\Cloud\Spanner\Tests\Unit\GapicBackoff; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Google\Cloud\Spanner\SpannerClient; use Google\Cloud\Core\Testing\GrpcTestTrait; @@ -29,7 +29,7 @@ class GapicBackoffTest extends TestCase { use GrpcTestTrait; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } diff --git a/Spanner/tests/Unit/InstanceConfigurationTest.php b/Spanner/tests/Unit/InstanceConfigurationTest.php index 65fd17f78c3d..154fce812dac 100644 --- a/Spanner/tests/Unit/InstanceConfigurationTest.php +++ b/Spanner/tests/Unit/InstanceConfigurationTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Spanner\Admin\Instance\V1\InstanceAdminClient; use Google\Cloud\Spanner\InstanceConfiguration; use Google\Cloud\Spanner\Tests\StubCreationTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -41,7 +41,7 @@ class InstanceConfigurationTest extends TestCase private $connection; private $configuration; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Unit/InstanceTest.php b/Spanner/tests/Unit/InstanceTest.php index dc249bcfe987..fc0f8e471150 100644 --- a/Spanner/tests/Unit/InstanceTest.php +++ b/Spanner/tests/Unit/InstanceTest.php @@ -30,8 +30,9 @@ use Google\Cloud\Spanner\Instance; use Google\Cloud\Spanner\Tests\StubCreationTrait; use Google\Cloud\Spanner\Backup; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -39,6 +40,7 @@ */ class InstanceTest extends TestCase { + use ExpectException; use GrpcTestTrait; use StubCreationTrait; @@ -51,7 +53,7 @@ class InstanceTest extends TestCase private $instance; private $lroConnection; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -293,11 +295,10 @@ public function testUpdateWithProcessingUnits() $this->instance->update(['processingUnits' => 500]); } - /** - * @expectedException \InvalidArgumentException - */ public function testUpdateRaisesInvalidArgument() { + $this->expectException('\InvalidArgumentException'); + $this->instance->update(['processingUnits' => 5000, 'nodeCount' => 5]); } diff --git a/Spanner/tests/Unit/KeyRangeTest.php b/Spanner/tests/Unit/KeyRangeTest.php index 6563882d2cb2..f3f0d422f800 100644 --- a/Spanner/tests/Unit/KeyRangeTest.php +++ b/Spanner/tests/Unit/KeyRangeTest.php @@ -19,18 +19,20 @@ use Google\Cloud\Spanner\KeyRange; use Google\Cloud\Core\Testing\GrpcTestTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class KeyRangeTest extends TestCase { + use ExpectException; use GrpcTestTrait; private $range; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -85,11 +87,10 @@ public function testSetStart() $this->assertEquals('startOpen', $this->range->types()['start']); } - /** - * @expectedException InvalidArgumentException - */ public function testSetStartInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->range->setStart('foo', ['foo']); } @@ -100,11 +101,10 @@ public function testSetEnd() $this->assertEquals('endOpen', $this->range->types()['end']); } - /** - * @expectedException InvalidArgumentException - */ public function testSetEndInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->range->setEnd('foo', ['foo']); } @@ -118,11 +118,10 @@ public function testKeyRangeObject() $this->assertEquals(['startOpen' => ['foo'], 'endClosed' => ['bar']], $res); } - /** - * @expectedException BadMethodCallException - */ public function testKeyRangeObjectBadRange() { + $this->expectException('BadMethodCallException'); + $this->range->keyRangeObject(); } diff --git a/Spanner/tests/Unit/KeySetTest.php b/Spanner/tests/Unit/KeySetTest.php index ad221ba0658c..97cc8cf6d952 100644 --- a/Spanner/tests/Unit/KeySetTest.php +++ b/Spanner/tests/Unit/KeySetTest.php @@ -20,12 +20,15 @@ use Google\Cloud\Spanner\KeyRange; use Google\Cloud\Spanner\KeySet; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class KeySetTest extends TestCase { + use ExpectException; + public function testAddRange() { $set = new KeySet; @@ -118,19 +121,17 @@ public function testMatchAll() $this->assertTrue($set->matchAll()); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidKeys() { + $this->expectException('InvalidArgumentException'); + new KeySet(['keys' => 'foo']); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidAll() { + $this->expectException('InvalidArgumentException'); + new KeySet(['all' => 1]); } diff --git a/Spanner/tests/Unit/NumericTest.php b/Spanner/tests/Unit/NumericTest.php index a0078a7ef6f8..c179d4fea20e 100644 --- a/Spanner/tests/Unit/NumericTest.php +++ b/Spanner/tests/Unit/NumericTest.php @@ -20,6 +20,7 @@ use Google\Cloud\Spanner\Numeric; use Google\Cloud\Spanner\V1\TypeCode; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -27,12 +28,15 @@ */ class NumericTest extends TestCase { + use ExpectException; + /** * @dataProvider invalidValueProvider - * @expectedException \InvalidArgumentException */ public function testInvalidValues($value) { + $this->expectException('\InvalidArgumentException'); + new Numeric($value); } diff --git a/Spanner/tests/Unit/OperationTest.php b/Spanner/tests/Unit/OperationTest.php index 0a21a4d82f26..b5eecbc9bf11 100644 --- a/Spanner/tests/Unit/OperationTest.php +++ b/Spanner/tests/Unit/OperationTest.php @@ -34,7 +34,7 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Transaction; use Google\Cloud\Spanner\V1\CommitResponse; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -55,7 +55,7 @@ class OperationTest extends TestCase private $operation; private $session; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Spanner/tests/Unit/ResultTest.php b/Spanner/tests/Unit/ResultTest.php index 0c0a5b431981..9a574d8f684c 100644 --- a/Spanner/tests/Unit/ResultTest.php +++ b/Spanner/tests/Unit/ResultTest.php @@ -24,7 +24,8 @@ use Google\Cloud\Spanner\ValueMapper; use Google\Cloud\Core\Testing\GrpcTestTrait; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -32,6 +33,7 @@ */ class ResultTest extends TestCase { + use ExpectException; use GrpcTestTrait; use ResultTestTrait; @@ -46,7 +48,7 @@ class ResultTest extends TestCase ] ]; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); } @@ -68,11 +70,10 @@ public function testIterator() $this->assertEquals($fixture['result']['value'], $result); } - /** - * @expectedException \Exception - */ public function testFailsWhenStreamThrowsUnrecoverableException() { + $this->expectException('\Exception'); + $result = $this->getResultClass( null, 'r', @@ -158,11 +159,10 @@ function () use ($chunks, &$timesCalled) { $this->assertEquals(2, $timesCalled); } - /** - * @expectedException Google\Cloud\Core\Exception\ServiceException - */ public function testThrowsExceptionWhenCannotRetry() { + $this->expectException('Google\Cloud\Core\Exception\ServiceException'); + $chunks = [ [ 'metadata' => $this->metadata, diff --git a/Spanner/tests/Unit/Session/CacheSessionPoolTest.php b/Spanner/tests/Unit/Session/CacheSessionPoolTest.php index c10f6e821679..51c6126ae49c 100644 --- a/Spanner/tests/Unit/Session/CacheSessionPoolTest.php +++ b/Spanner/tests/Unit/Session/CacheSessionPoolTest.php @@ -28,7 +28,8 @@ use Psr\Cache\CacheItemPoolInterface; use Prophecy\Argument; use Prophecy\Argument\ArgumentsWildcard; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -36,6 +37,7 @@ */ class CacheSessionPoolTest extends TestCase { + use ExpectException; use GrpcTestTrait; const CACHE_KEY_TEMPLATE = CacheSessionPool::CACHE_KEY_TEMPLATE; @@ -46,7 +48,7 @@ class CacheSessionPoolTest extends TestCase private $time; private $cacheKey; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); putenv('GOOGLE_CLOUD_SYSV_ID=U'); @@ -83,11 +85,10 @@ public function badConfigDataProvider() ]; } - /** - * @expectedException \RuntimeException - */ public function testAcquireThrowsExceptionWhenMaxCyclesMet() { + $this->expectException('\RuntimeException'); + $config = [ 'maxSessions' => 1, 'maxCyclesToWaitForSession' => 1 @@ -110,11 +111,10 @@ public function testAcquireThrowsExceptionWhenMaxCyclesMet() $pool->acquire(); } - /** - * @expectedException \RuntimeException - */ public function testAcquireThrowsExceptionWithNoAvailableSessions() { + $this->expectException('\RuntimeException'); + $config = [ 'maxSessions' => 1, 'shouldWaitForSession' => false @@ -843,11 +843,10 @@ public function testMaintainException() $this->assertEquals($data, $gotData); } - /** - * @expectedException \LogicException - */ public function testMaintainNoDatabase() { + $this->expectException('\LogicException'); + $cache = $this->getCacheItemPool(); $pool = new CacheSessionPoolStub($cache, [], $this->time); $pool->maintain(); diff --git a/Spanner/tests/Unit/SnapshotTest.php b/Spanner/tests/Unit/SnapshotTest.php index 25c11132b1d6..6f20882ea695 100644 --- a/Spanner/tests/Unit/SnapshotTest.php +++ b/Spanner/tests/Unit/SnapshotTest.php @@ -23,19 +23,21 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Core\Testing\GrpcTestTrait; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class SnapshotTest extends TestCase { + use ExpectException; use GrpcTestTrait; private $timestamp; private $snapshot; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -73,11 +75,10 @@ public function testReadTimestamp() $this->assertEquals($this->timestamp, $this->snapshot->readTimestamp()); } - /** - * @expectedException InvalidArgumentException - */ public function testWithInvalidTimestamp() { + $this->expectException('InvalidArgumentException'); + $args = [ 'readTimestamp' => 'foo' ]; @@ -89,11 +90,10 @@ public function testWithInvalidTimestamp() ); } - /** - * @expectedException BadMethodCallException - */ public function testSingleUseFailsOnSecondUse() { + $this->expectException('BadMethodCallException'); + $operation = $this->prophesize(Operation::class); $operation->execute(Argument::any(), Argument::any(), Argument::any()) ->shouldBeCalled(); diff --git a/Spanner/tests/Unit/SpannerClientTest.php b/Spanner/tests/Unit/SpannerClientTest.php index 4cd3d3c61faa..9742d3ff45e3 100644 --- a/Spanner/tests/Unit/SpannerClientTest.php +++ b/Spanner/tests/Unit/SpannerClientTest.php @@ -39,14 +39,16 @@ use Google\Cloud\Spanner\SpannerClient; use Google\Cloud\Spanner\Tests\StubCreationTrait; use Google\Cloud\Spanner\Timestamp; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class SpannerClientTest extends TestCase { + use ExpectException; use GrpcTestTrait; use StubCreationTrait; @@ -58,7 +60,7 @@ class SpannerClientTest extends TestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -269,10 +271,11 @@ public function testCreateInstanceWithProcessingUnits() /** * @group spanner-admin - * @expectedException \InvalidArgumentException */ public function testCreateInstanceRaisesInvalidArgument() { + $this->expectException('\InvalidArgumentException'); + $config = $this->prophesize(InstanceConfiguration::class); $this->client->createInstance($config->reveal(), self::INSTANCE, [ diff --git a/Spanner/tests/Unit/StructTypeTest.php b/Spanner/tests/Unit/StructTypeTest.php index 7ea652e42b8a..251e71b1d1cb 100644 --- a/Spanner/tests/Unit/StructTypeTest.php +++ b/Spanner/tests/Unit/StructTypeTest.php @@ -20,7 +20,8 @@ use Google\Cloud\Spanner\ArrayType; use Google\Cloud\Spanner\Database; use Google\Cloud\Spanner\StructType; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -28,9 +29,11 @@ */ class StructTypeTest extends TestCase { + use ExpectException; + private $definition; - public function setUp() + public function set_up() { $this->definition = [ [ @@ -74,21 +77,21 @@ public function testAddUnnamed() ]); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Field type `foo` is not valid. - */ public function testAddInvalidType() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Field type `foo` is not valid.'); + (new StructType)->add('name', 'foo'); } /** - * @expectedException \InvalidArgumentException * @dataProvider definitionTypes */ public function testInvalidTypeDefinition($type) { + $this->expectException('\InvalidArgumentException'); + (new StructType)->add('foo', $type); } diff --git a/Spanner/tests/Unit/StructValueTest.php b/Spanner/tests/Unit/StructValueTest.php index 524cf55544d5..bf5104928431 100644 --- a/Spanner/tests/Unit/StructValueTest.php +++ b/Spanner/tests/Unit/StructValueTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Spanner\Tests\Unit; use Google\Cloud\Spanner\StructValue; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group spanner @@ -28,7 +28,7 @@ class StructValueTest extends TestCase { private $values; - public function setUp() + public function set_up() { $this->values = [ [ diff --git a/Spanner/tests/Unit/TimestampTest.php b/Spanner/tests/Unit/TimestampTest.php index 2d22e03f33c2..05082009db05 100644 --- a/Spanner/tests/Unit/TimestampTest.php +++ b/Spanner/tests/Unit/TimestampTest.php @@ -19,19 +19,21 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Core\Testing\GrpcTestTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group spanner */ class TimestampTest extends TestCase { + use AssertIsType; use GrpcTestTrait; private $dt; private $ts; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -62,6 +64,6 @@ public function testCast() public function testType() { - $this->assertInternalType('int', $this->ts->type()); + $this->assertIsInt($this->ts->type()); } } diff --git a/Spanner/tests/Unit/TransactionConfigurationTraitTest.php b/Spanner/tests/Unit/TransactionConfigurationTraitTest.php index 75eae0be76f7..826bb67a5f86 100644 --- a/Spanner/tests/Unit/TransactionConfigurationTraitTest.php +++ b/Spanner/tests/Unit/TransactionConfigurationTraitTest.php @@ -23,7 +23,8 @@ use Google\Cloud\Spanner\Session\SessionPoolInterface; use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\TransactionConfigurationTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -31,6 +32,7 @@ */ class TransactionConfigurationTraitTest extends TestCase { + use ExpectException; use GrpcTestTrait; use TimeTrait; @@ -41,7 +43,7 @@ class TransactionConfigurationTraitTest extends TestCase private $duration; private $dur = []; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -141,47 +143,42 @@ public function testConfigureSnapshotOptionsExactStaleness() $this->assertEquals($this->dur, $res['readOnly']['exactStaleness']); } - /** - * @expectedException BadMethodCallException - */ public function testTransactionSelectorInvalidContext() { + $this->expectException('BadMethodCallException'); + $args = ['transactionType' => 'foo']; $this->impl->proxyTransactionSelector($args); } - /** - * @expectedException BadMethodCallException - */ public function testConfigureSnapshotOptionsInvalidExactStaleness() { + $this->expectException('BadMethodCallException'); + $args = ['exactStaleness' => 'foo']; $this->impl->proxyConfigureSnapshotOptions($args); } - /** - * @expectedException BadMethodCallException - */ public function testConfigureSnapshotOptionsInvalidMaxStaleness() { + $this->expectException('BadMethodCallException'); + $args = ['maxStaleness' => 'foo']; $this->impl->proxyConfigureSnapshotOptions($args); } - /** - * @expectedException BadMethodCallException - */ public function testConfigureSnapshotOptionsInvalidMinReadTimestamp() { + $this->expectException('BadMethodCallException'); + $args = ['minReadTimestamp' => 'foo']; $this->impl->proxyConfigureSnapshotOptions($args); } - /** - * @expectedException BadMethodCallException - */ public function testConfigureSnapshotOptionsInvalidReadTimestamp() { + $this->expectException('BadMethodCallException'); + $args = ['readTimestamp' => 'foo']; $this->impl->proxyConfigureSnapshotOptions($args); } diff --git a/Spanner/tests/Unit/TransactionTest.php b/Spanner/tests/Unit/TransactionTest.php index d4e9049d7a4f..1a4c39b9c067 100644 --- a/Spanner/tests/Unit/TransactionTest.php +++ b/Spanner/tests/Unit/TransactionTest.php @@ -31,14 +31,16 @@ use Google\Cloud\Spanner\Tests\StubCreationTrait; use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Transaction; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner */ class TransactionTest extends TestCase { + use ExpectException; use GrpcTestTrait; use OperationRefreshTrait; use ResultGeneratorTrait; @@ -64,7 +66,7 @@ class TransactionTest extends TestCase private $transaction; private $singleUseTransaction; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -100,11 +102,10 @@ public function setUp() $this->singleUseTransaction = TestHelpers::stub(Transaction::class, $args, $props); } - /** - * @expectedException InvalidArgumentException - */ public function testSingleUseTagError() { + $this->expectException('InvalidArgumentException'); + new Transaction( $this->operation, $this->session, @@ -395,11 +396,10 @@ public function testExecuteUpdateBatchError() $this->assertEquals($statements[2], $res->error()['statement']); } - /** - * @expectedException InvalidArgumentException - */ public function testExecuteUpdateBatchInvalidStatement() { + $this->expectException('InvalidArgumentException'); + $this->transaction->executeUpdateBatch([ ['foo' => 'bar'] ]); @@ -427,11 +427,10 @@ private function bdmlStatements() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testExecuteUpdateNonDml() { + $this->expectException('InvalidArgumentException'); + $sql = 'UPDATE foo SET bar = @bar'; $this->connection->executeStreamingSql(Argument::allOf( Argument::withEntry('sql', $sql), @@ -527,11 +526,10 @@ public function testCommitWithReturnCommitStats() $this->assertEquals(['mutationCount' => 1], $this->transaction->getCommitStats()); } - /** - * @expectedException BadMethodCallException - */ public function testCommitInvalidState() { + $this->expectException('BadMethodCallException'); + $this->transaction->___setProperty('state', 'foo'); $this->transaction->commit(); } @@ -546,11 +544,10 @@ public function testRollback() $this->transaction->rollback(); } - /** - * @expectedException BadMethodCallException - */ public function testRollbackInvalidState() { + $this->expectException('BadMethodCallException'); + $this->transaction->___setProperty('state', 'foo'); $this->transaction->rollback(); } @@ -568,11 +565,10 @@ public function testState() $this->assertEquals(Transaction::STATE_COMMITTED, $this->transaction->state()); } - /** - * @expectedException BadMethodCallException - */ public function testInvalidReadContext() { + $this->expectException('BadMethodCallException'); + $this->singleUseTransaction->execute('foo'); } diff --git a/Spanner/tests/Unit/TransactionTypeTest.php b/Spanner/tests/Unit/TransactionTypeTest.php index cd7a52a8e19b..200a7a5f38df 100644 --- a/Spanner/tests/Unit/TransactionTypeTest.php +++ b/Spanner/tests/Unit/TransactionTypeTest.php @@ -34,8 +34,9 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\Transaction; use Google\Cloud\Spanner\V1\SpannerClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -43,6 +44,7 @@ */ class TransactionTypeTest extends TestCase { + use ExpectException; use GrpcTestTrait; use ResultTestTrait; use StubCreationTrait; @@ -58,7 +60,7 @@ class TransactionTypeTest extends TestCase private $timestamp; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); @@ -218,11 +220,10 @@ public function testDatabaseSingleUseSnapshotMinReadTimestampAndMaxStaleness($ch $result = $snapshot->execute('SELECT * FROM Table')->rows()->current(); } - /** - * @expectedException BadMethodCallException - */ public function testDatabasePreAllocatedSnapshotMinReadTimestamp() { + $this->expectException('BadMethodCallException'); + $time = $this->parseTimeString($this->timestamp); $timestamp = new Timestamp($time[0], $time[1]); @@ -239,11 +240,10 @@ public function testDatabasePreAllocatedSnapshotMinReadTimestamp() ]); } - /** - * @expectedException BadMethodCallException - */ public function testDatabasePreAllocatedSnapshotMaxStaleness() { + $this->expectException('BadMethodCallException'); + $seconds = 1; $nanos = 2; @@ -761,11 +761,10 @@ public function testTransactionPreAllocatedRollback() $t->rollback(); } - /** - * @expectedException BadMethodCallException - */ public function testTransactionSingleUseRollback() { + $this->expectException('BadMethodCallException'); + $this->connection->beginTransaction(Argument::any())->shouldNotbeCalled(); $this->connection->rollback(Argument::any())->shouldNotbeCalled(); diff --git a/Spanner/tests/Unit/ValueMapperTest.php b/Spanner/tests/Unit/ValueMapperTest.php index 025ad3c6e53c..885e802b3478 100644 --- a/Spanner/tests/Unit/ValueMapperTest.php +++ b/Spanner/tests/Unit/ValueMapperTest.php @@ -31,7 +31,8 @@ use Google\Cloud\Spanner\Timestamp; use Google\Cloud\Spanner\ValueMapper; use Google\Cloud\Spanner\V1\TypeAnnotationCode; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group spanner @@ -39,13 +40,14 @@ */ class ValueMapperTest extends TestCase { + use ExpectException; use GrpcTestTrait; const FORMAT_TEST_VALUE = 'abc'; private $mapper; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); $this->mapper = new ValueMapper(false); @@ -104,11 +106,10 @@ public function testFormatParamsForExecuteSqlArray() $this->assertEquals(Database::TYPE_STRING, $res['paramTypes']['array']['arrayElementType']['code']); } - /** - * @expectedException InvalidArgumentException - */ public function testFormatParamsForExecuteSqlInvalidTypes() { + $this->expectException('InvalidArgumentException'); + $this->mapper->formatParamsForExecuteSql(['array' => ['foo', 3.1515]]); } @@ -153,11 +154,10 @@ public function testFormatParamsForExecuteSqlValueInterface() $this->assertEquals(Database::TYPE_BYTES, $res['paramTypes']['bytes']['code']); } - /** - * @expectedException InvalidArgumentException - */ public function testFormatParamsForExecuteSqlInvalidObjectType() { + $this->expectException('InvalidArgumentException'); + $params = [ 'bad' => $this ]; @@ -165,11 +165,10 @@ public function testFormatParamsForExecuteSqlInvalidObjectType() $this->mapper->formatParamsForExecuteSql($params); } - /** - * @expectedException BadMethodCallException - */ public function testFormatParamsForExecuteSqlNullValueMissingType() { + $this->expectException('BadMethodCallException'); + $params = [ 'null' => null ]; @@ -276,12 +275,11 @@ public function testFormatParamsForExecuteSqlNullArray() ], $res['paramTypes']); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Array data does not match given array parameter type. - */ public function testFormatParamsForExecuteSqlArrayMismatchedDefinition() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Array data does not match given array parameter type.'); + $params = [ 'foo' => [1,2,3] ]; @@ -319,12 +317,11 @@ public function testFormatParamsForExecuteSqlArrayForCustomTypes() ], $res['paramTypes']); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Array parameter types must be an instance of Google\Cloud\Spanner\ArrayType. - */ public function testFormatParamsForExecuteSqlArrayInvalidDefinition() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Array parameter types must be an instance of Google\Cloud\Spanner\ArrayType.'); + $params = [ 'foo' => ['bar'] ]; @@ -336,12 +333,11 @@ public function testFormatParamsForExecuteSqlArrayInvalidDefinition() $this->mapper->formatParamsForExecuteSql($params, $types); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Array value must be an array or null. - */ public function testFormatParamsForExecuteSqlArrayInvalidValue() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Array value must be an array or null.'); + $params = [ 'foo' => 'hello' ]; @@ -417,12 +413,15 @@ public function testFormatParamsForExecuteSqlStruct() /** * @codingStandardsIgnoreStart - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Struct parameter types must be declared explicitly, and must be an instance of Google\Cloud\Spanner\StructType. * @codingStandardsIgnoreEnd */ public function testFormatParamsForExecuteSqlStructInvalidDefinition() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage( + 'Struct parameter types must be declared explicitly, and must be an ' + . 'instance of Google\Cloud\Spanner\StructType.' + ); $params = [ 'foo' => [ 'hello' => 'world' @@ -438,12 +437,15 @@ public function testFormatParamsForExecuteSqlStructInvalidDefinition() /** * @codingStandardsIgnoreStart - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Struct value must be an array an instance of `Google\Cloud\Spanner\StructValue` or null. * @codingStandardsIgnoreEnd */ public function testFormatParamsForExecuteSqlInvalidStructValue() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage( + 'Struct value must be an array an instance of `Google\Cloud\Spanner\StructValue` or null.' + ); + $params = [ 'foo' => 'bar' ]; @@ -675,12 +677,13 @@ public function testFormatParamsForExecuteSqlStdClassValue() ], $res['paramTypes']); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Values of type `\stdClass` are interpreted as structs and must define their types. - */ public function testFormatParamsForExecuteSqlStdClassMissingDefinition() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage( + 'Values of type `\stdClass` are interpreted as structs and must define their types.' + ); + $this->mapper->formatParamsForExecuteSql([ 'foo' => (object) ['foo' => 'bar'] ]); @@ -721,11 +724,10 @@ public function simpleTypeValues() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testDecodeValuesThrowsExceptionWithInvalidFormat() { + $this->expectException('\InvalidArgumentException'); + $res = $this->mapper->decodeValues( $this->createField(Database::TYPE_STRING), $this->createRow(self::FORMAT_TEST_VALUE), @@ -848,11 +850,10 @@ public function testDecodeValuesFloatNegativeInfinity() $this->assertLessThan(0, $res['rowName']); } - /** - * @expectedException RuntimeException - */ public function testDecodeValuesFloatError() { + $this->expectException('RuntimeException'); + $res = $this->mapper->decodeValues( $this->createField(Database::TYPE_FLOAT64), $this->createRow('foo'), diff --git a/Speech/composer.json b/Speech/composer.json index 1647e5314703..f1437c564fe8 100644 --- a/Speech/composer.json +++ b/Speech/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Speech/phpunit-snippets.xml.dist b/Speech/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Speech/phpunit-snippets.xml.dist +++ b/Speech/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Speech/tests/Snippet/OperationTest.php b/Speech/tests/Snippet/OperationTest.php index ef24bfd00a2d..59dce573625c 100644 --- a/Speech/tests/Snippet/OperationTest.php +++ b/Speech/tests/Snippet/OperationTest.php @@ -34,7 +34,7 @@ class OperationTest extends SnippetTestCase private $connection; private $operation; - public function setUp() + public function set_up() { $this->opData = [ 'done' => true, diff --git a/Speech/tests/Snippet/ResultTest.php b/Speech/tests/Snippet/ResultTest.php index c9b737e334d2..3ef7898a5c3d 100644 --- a/Speech/tests/Snippet/ResultTest.php +++ b/Speech/tests/Snippet/ResultTest.php @@ -33,7 +33,7 @@ class ResultTest extends SnippetTestCase private $resultData; private $result; - public function setUp() + public function set_up() { $this->transcript = 'hello world'; $this->resultData = [ diff --git a/Speech/tests/Snippet/SpeechClientTest.php b/Speech/tests/Snippet/SpeechClientTest.php index d61a6f7501ca..302941f35a95 100644 --- a/Speech/tests/Snippet/SpeechClientTest.php +++ b/Speech/tests/Snippet/SpeechClientTest.php @@ -33,7 +33,7 @@ class SpeechClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->testFile = "'" . __DIR__ . '/fixtures/demo.flac' . "'"; $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Speech/tests/Snippet/V1/SpeechClientTest.php b/Speech/tests/Snippet/V1/SpeechClientTest.php index 0e5f7dc4af82..34cb929dfa9e 100644 --- a/Speech/tests/Snippet/V1/SpeechClientTest.php +++ b/Speech/tests/Snippet/V1/SpeechClientTest.php @@ -34,7 +34,7 @@ class SpeechClientTest extends SnippetTestCase private $client; private $transport; - public function setUp() + public function set_up() { $this->transport = $this->prophesize(TransportInterface::class); $this->client = new SpeechClient([ diff --git a/Speech/tests/Unit/Connection/RestTest.php b/Speech/tests/Unit/Connection/RestTest.php index 426953cfa0e3..9153d1c796cd 100644 --- a/Speech/tests/Unit/Connection/RestTest.php +++ b/Speech/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Speech\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Speech/tests/Unit/OperationTest.php b/Speech/tests/Unit/OperationTest.php index c37b85493bed..45e40af32308 100644 --- a/Speech/tests/Unit/OperationTest.php +++ b/Speech/tests/Unit/OperationTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Speech\Operation; use Google\Cloud\Speech\Result; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group speech @@ -35,7 +35,7 @@ class OperationTest extends TestCase 'name' => 'abcdefg' ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/Speech/tests/Unit/ResultTest.php b/Speech/tests/Unit/ResultTest.php index 9ed6ac36b87b..5328edc8a057 100644 --- a/Speech/tests/Unit/ResultTest.php +++ b/Speech/tests/Unit/ResultTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Speech\Result; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group speech @@ -30,7 +30,7 @@ class ResultTest extends TestCase private $confidence; private $result; - public function setUp() + public function set_up() { $this->transcript = 'testing'; $this->confidence = 1.0; diff --git a/Speech/tests/Unit/SpeechClientTest.php b/Speech/tests/Unit/SpeechClientTest.php index d861df895481..3f7712bd3ce3 100644 --- a/Speech/tests/Unit/SpeechClientTest.php +++ b/Speech/tests/Unit/SpeechClientTest.php @@ -23,20 +23,23 @@ use Google\Cloud\Speech\Result; use Google\Cloud\Speech\SpeechClient; use Google\Cloud\Storage\StorageObject; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group speech */ class SpeechClientTest extends TestCase { + use ExpectException; + const GCS_URI = 'gs://bucket/object'; private $client; private $connection; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(SpeechClient::class, [ ['languageCode' => 'en-US'] @@ -44,11 +47,10 @@ public function setUp() $this->connection = $this->prophesize(ConnectionInterface::class); } - /** - * @expectedException \InvalidArgumentException - */ public function testThrowsExceptionWithoutLanguageCode() { + $this->expectException('\InvalidArgumentException'); + $client = TestHelpers::stub(SpeechClient::class); $client->recognize(self::GCS_URI); } diff --git a/Speech/tests/Unit/SpeechHelpersTraitTest.php b/Speech/tests/Unit/SpeechHelpersTraitTest.php index 1a31c53a9210..375dc32aa836 100644 --- a/Speech/tests/Unit/SpeechHelpersTraitTest.php +++ b/Speech/tests/Unit/SpeechHelpersTraitTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Speech\SpeechHelpersTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group speech @@ -30,7 +30,7 @@ class SpeechHelpersTraitTest extends TestCase private $implementation; - public function setUp() + public function set_up() { $this->implementation = TestHelpers::impl(SpeechHelpersTrait::class); } diff --git a/Speech/tests/Unit/V1/SpeechClientExtensionTest.php b/Speech/tests/Unit/V1/SpeechClientExtensionTest.php index 1a20b8ac83db..c0c6dcd05d08 100644 --- a/Speech/tests/Unit/V1/SpeechClientExtensionTest.php +++ b/Speech/tests/Unit/V1/SpeechClientExtensionTest.php @@ -29,7 +29,7 @@ use Google\Cloud\Speech\V1\StreamingRecognizeRequest; use Google\Cloud\Speech\V1\StreamingRecognizeResponse; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group speech @@ -41,7 +41,7 @@ class SpeechClientExtensionTest extends TestCase /** @var TransportInterface */ private $transport; - public function setUp() + public function set_up() { $this->transport = $this->prophesize(TransportInterface::class); $this->client = new SpeechClient([ diff --git a/SqlAdmin/composer.json b/SqlAdmin/composer.json index d50bc5260c43..e237dfc13be6 100644 --- a/SqlAdmin/composer.json +++ b/SqlAdmin/composer.json @@ -27,7 +27,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Storage/composer.json b/Storage/composer.json index eb344c52c966..3c224ada4d2b 100644 --- a/Storage/composer.json +++ b/Storage/composer.json @@ -8,7 +8,8 @@ "google/crc32": "^0.1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Storage/phpunit-snippets.xml.dist b/Storage/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Storage/phpunit-snippets.xml.dist +++ b/Storage/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Storage/tests/Snippet/AclTest.php b/Storage/tests/Snippet/AclTest.php index 5d5b90ce67ea..7bfdc96da44f 100644 --- a/Storage/tests/Snippet/AclTest.php +++ b/Storage/tests/Snippet/AclTest.php @@ -31,7 +31,7 @@ class AclTest extends SnippetTestCase private $connection; private $acl; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->acl = TestHelpers::stub(Acl::class, [ diff --git a/Storage/tests/Snippet/BucketTest.php b/Storage/tests/Snippet/BucketTest.php index bb59f0b73c70..1ee42e8f987e 100644 --- a/Storage/tests/Snippet/BucketTest.php +++ b/Storage/tests/Snippet/BucketTest.php @@ -39,12 +39,14 @@ use Google\Cloud\Storage\StorageObject; use GuzzleHttp\Promise; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group storage */ class BucketTest extends SnippetTestCase { + use AssertStringContains; use KeyPairGenerateTrait; const BUCKET = 'my-bucket'; @@ -71,7 +73,7 @@ class BucketTest extends SnippetTestCase ] ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->connection->projectId() @@ -735,9 +737,9 @@ public function testSignedUrl() $this->bucket->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket', $res->returnVal()); - $this->assertContains('Expires=', $res->returnVal()); - $this->assertContains('Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket', $res->returnVal()); + $this->assertStringContainsString('Expires=', $res->returnVal()); + $this->assertStringContainsString('Signature=', $res->returnVal()); } public function testSignedUrlV4() @@ -765,8 +767,8 @@ public function testSignedUrlV4() $this->bucket->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket', $res->returnVal()); - $this->assertContains('X-Goog-Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket', $res->returnVal()); + $this->assertStringContainsString('X-Goog-Signature=', $res->returnVal()); } public function testGenerateSignedPostPolicyV4() @@ -798,7 +800,7 @@ public function testGenerateSignedPostPolicyV4() $res = $snippet->invoke('policy'); - $this->assertContains('https://storage.googleapis.com/my-bucket', $res->returnVal()['url']); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket', $res->returnVal()['url']); $this->assertEquals($objectName, $res->returnVal()['fields']['key']); } diff --git a/Storage/tests/Snippet/CreatedHmacKeyTest.php b/Storage/tests/Snippet/CreatedHmacKeyTest.php index 0623f91630c9..353fa43891ee 100644 --- a/Storage/tests/Snippet/CreatedHmacKeyTest.php +++ b/Storage/tests/Snippet/CreatedHmacKeyTest.php @@ -37,7 +37,7 @@ class CreatedHmacKeyTest extends SnippetTestCase private $connection; private $createdKey; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Storage/tests/Snippet/HmacKeyTest.php b/Storage/tests/Snippet/HmacKeyTest.php index 40d761deef96..87ae4c0c1e50 100644 --- a/Storage/tests/Snippet/HmacKeyTest.php +++ b/Storage/tests/Snippet/HmacKeyTest.php @@ -39,7 +39,7 @@ class HmacKeyTest extends SnippetTestCase 'accessId' => 'foo' ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); diff --git a/Storage/tests/Snippet/LifecycleTest.php b/Storage/tests/Snippet/LifecycleTest.php index 849de18872e8..1869159a8e4d 100644 --- a/Storage/tests/Snippet/LifecycleTest.php +++ b/Storage/tests/Snippet/LifecycleTest.php @@ -39,7 +39,7 @@ class LifecycleTest extends SnippetTestCase 'isLive' => true ]; - public function setUp() + public function set_up() { $this->lifecycle = new Lifecycle; } diff --git a/Storage/tests/Snippet/NotificationTest.php b/Storage/tests/Snippet/NotificationTest.php index add13b1be30c..47b76026fbf6 100644 --- a/Storage/tests/Snippet/NotificationTest.php +++ b/Storage/tests/Snippet/NotificationTest.php @@ -38,7 +38,7 @@ class NotificationTest extends SnippetTestCase private $connection; private $notification; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->notification = TestHelpers::stub(Notification::class, [ diff --git a/Storage/tests/Snippet/StorageClientTest.php b/Storage/tests/Snippet/StorageClientTest.php index 45a77d4abbda..87b401fcf674 100644 --- a/Storage/tests/Snippet/StorageClientTest.php +++ b/Storage/tests/Snippet/StorageClientTest.php @@ -40,7 +40,7 @@ class StorageClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->connection->projectId() diff --git a/Storage/tests/Snippet/StorageObjectTest.php b/Storage/tests/Snippet/StorageObjectTest.php index 7436afed6511..bb976b5ff1f4 100644 --- a/Storage/tests/Snippet/StorageObjectTest.php +++ b/Storage/tests/Snippet/StorageObjectTest.php @@ -34,12 +34,14 @@ use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group storage */ class StorageObjectTest extends SnippetTestCase { + use AssertStringContains; use KeyPairGenerateTrait; const OBJECT = 'my-object'; @@ -48,7 +50,7 @@ class StorageObjectTest extends SnippetTestCase private $connection; private $object; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->object = TestHelpers::stub(StorageObject::class, [ @@ -456,9 +458,9 @@ public function testSignedUrl() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); - $this->assertContains('Expires=', $res->returnVal()); - $this->assertContains('Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); + $this->assertStringContainsString('Expires=', $res->returnVal()); + $this->assertStringContainsString('Signature=', $res->returnVal()); } public function testSignedUrlUpdate() @@ -486,9 +488,9 @@ public function testSignedUrlUpdate() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); - $this->assertContains('Expires=', $res->returnVal()); - $this->assertContains('Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); + $this->assertStringContainsString('Expires=', $res->returnVal()); + $this->assertStringContainsString('Signature=', $res->returnVal()); } public function testSignedUrlV4() @@ -516,8 +518,8 @@ public function testSignedUrlV4() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); - $this->assertContains('X-Goog-Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); + $this->assertStringContainsString('X-Goog-Signature=', $res->returnVal()); } public function testSignedUrlBucketBoundHostname() @@ -545,7 +547,7 @@ public function testSignedUrlBucketBoundHostname() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://cdn.example.com/my-object', $res->returnVal()); + $this->assertStringContainsString('https://cdn.example.com/my-object', $res->returnVal()); } public function testSignedUrlVirtualHostedStyle() @@ -573,7 +575,7 @@ public function testSignedUrlVirtualHostedStyle() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://my-bucket.storage.googleapis.com/my-object', $res->returnVal()); + $this->assertStringContainsString('https://my-bucket.storage.googleapis.com/my-object', $res->returnVal()); } public function testSignedUploadUrl() @@ -602,9 +604,9 @@ public function testSignedUploadUrl() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); - $this->assertContains('Expires=', $res->returnVal()); - $this->assertContains('Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); + $this->assertStringContainsString('Expires=', $res->returnVal()); + $this->assertStringContainsString('Signature=', $res->returnVal()); } public function testSignedUploadUrlV4() @@ -633,8 +635,8 @@ public function testSignedUploadUrlV4() $this->object->___setProperty('connection', $conn->reveal()); $res = $snippet->invoke('url'); - $this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); - $this->assertContains('X-Goog-Signature=', $res->returnVal()); + $this->assertStringContainsString('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal()); + $this->assertStringContainsString('X-Goog-Signature=', $res->returnVal()); } /** @@ -676,7 +678,7 @@ public function testBeginSignedUploadSession($snippet) public function signedUploadSessionSnippet() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [$this->snippetFromMethod(StorageObject::class, 'beginSignedUploadSession')], diff --git a/Storage/tests/System/HmacKeyTest.php b/Storage/tests/System/HmacKeyTest.php index 7e8c5f729b28..d135100d5141 100644 --- a/Storage/tests/System/HmacKeyTest.php +++ b/Storage/tests/System/HmacKeyTest.php @@ -28,9 +28,9 @@ class HmacKeyTest extends StorageTestCase { private static $serviceAccountEmail; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$serviceAccountEmail = json_decode( file_get_contents(getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')), diff --git a/Storage/tests/System/IamConfigurationTest.php b/Storage/tests/System/IamConfigurationTest.php index d711a4165a0a..ea07cc75f17d 100644 --- a/Storage/tests/System/IamConfigurationTest.php +++ b/Storage/tests/System/IamConfigurationTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Core\Exception\BadRequestException; use Google\Cloud\Storage\StorageObject; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -26,6 +27,8 @@ */ class IamConfigurationTest extends StorageTestCase { + use ExpectException; + public function testUniformBucketLevelAccess() { $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX)); @@ -38,22 +41,20 @@ public function testUniformBucketLevelAccess() $this->assertFalse($bucket->info()['iamConfiguration']['uniformBucketLevelAccess']['enabled']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testUniformBucketLevelAccessAclFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX)); $bucket->update($this->ublaConfig()); $bucket->acl()->get(); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testObjectPolicyOnlyAclFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX)); $keyfile = json_decode(file_get_contents(getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')), true); @@ -141,20 +142,18 @@ public function publicAccessSetting() ]; } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testSetBucketAclToPublicAccessFailsWithPublicAccessPrevention() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX), $this->papConfig()); $bucket->acl()->add('allUsers', 'READER'); } - /** - * @expectedException Google\Cloud\Core\Exception\FailedPreconditionException - */ public function testSetObjectAclToPublicAccessFailsWithPublicAccessPrevention() { + $this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException'); + $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX), $this->papConfig()); $object = $bucket->upload('hello world', [ 'name' => 'helloworld.txt' @@ -164,11 +163,10 @@ public function testSetObjectAclToPublicAccessFailsWithPublicAccessPrevention() $object->acl()->add('allUsers', 'READER'); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testInvalidPublicAccessPreventionSettingFailsOnCreate() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $config = $this->papConfig(); $config['iamConfiguration']['publicAccessPrevention'] = 'well maybe we should? idk what do you think'; self::createBucket(self::$client, uniqid(self::TESTING_PREFIX), $config + [ @@ -177,11 +175,10 @@ public function testInvalidPublicAccessPreventionSettingFailsOnCreate() ]); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testInvalidPublicAccessPreventionSettingFailsOnUpdate() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + try { $bucket = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX)); } catch (BadRequestException $e) { diff --git a/Storage/tests/System/IamTest.php b/Storage/tests/System/IamTest.php index 94b4fe363040..435943bc8040 100644 --- a/Storage/tests/System/IamTest.php +++ b/Storage/tests/System/IamTest.php @@ -17,15 +17,19 @@ namespace Google\Cloud\Storage\Tests\System; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; + /** * @group storage * @group storage-iam */ class IamTest extends StorageTestCase { + use AssertStringContains; + private $b; - public function setUp() + public function set_up() { $this->b = self::createBucket(self::$client, uniqid(self::TESTING_PREFIX)); $this->b->update($this->bucketConfig()); @@ -75,7 +79,7 @@ public function testSetPolicy() $iam->setPolicy($policy); $policy = $iam->reload(); - $this->assertContains( + $this->assertStringContainsString( [ 'role' => 'roles/storage.legacyBucketReader', 'members' => ['allUsers', 'projectViewer:' . $projectId] @@ -106,7 +110,7 @@ public function testGetModifySetConditionalPolicy() $policy['bindings'][] = $conditionalBinding; $iam->setPolicy($policy); $policy = $iam->reload(['requestedPolicyVersion' => 3]); - $this->assertContains( + $this->assertStringContainsString( $conditionalBinding, $policy['bindings'] ); diff --git a/Storage/tests/System/KmsTest.php b/Storage/tests/System/KmsTest.php index 1034d79d77d2..c2854a8d9c75 100644 --- a/Storage/tests/System/KmsTest.php +++ b/Storage/tests/System/KmsTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Core\Testing\System\KeyManager; use Google\Cloud\Storage\StorageObject; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group storage @@ -26,6 +27,8 @@ */ class KmsTest extends StorageTestCase { + use AssertStringContains; + const DATA = 'data'; const KEY_RING_ID = 'kms-kr'; const CRYPTO_KEY_ID_1 = 'key1'; @@ -34,9 +37,9 @@ class KmsTest extends StorageTestCase private static $keyName1; private static $keyName2; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $encryption = new KeyManager( @@ -55,7 +58,7 @@ public function testUpload() { $object = $this->upload(); - $this->assertContains(self::$keyName1, $object->info()['kmsKeyName']); + $this->assertStringContainsString(self::$keyName1, $object->info()['kmsKeyName']); $this->assertEquals(self::DATA, $object->downloadAsString()); } @@ -69,7 +72,7 @@ public function testUploadWithDefaultKmsKeyNameOnBucket() $object = $this->upload(['metadata' => null]); - $this->assertContains(self::$keyName1, $object->info()['kmsKeyName']); + $this->assertStringContainsString(self::$keyName1, $object->info()['kmsKeyName']); $this->assertEquals(self::DATA, $object->downloadAsString()); // Reset default to none @@ -94,7 +97,7 @@ public function testUploadExplicitKmsKeyOverridesDefaultOnBucket() ] ]); - $this->assertContains(self::$keyName2, $object->info()['kmsKeyName']); + $this->assertStringContainsString(self::$keyName2, $object->info()['kmsKeyName']); $this->assertEquals(self::DATA, $object->downloadAsString()); // Reset default to none @@ -114,7 +117,7 @@ public function testRotatesKmsKeys() ]; $rewrittenObject = $object->rewrite(self::$bucket, $rewriteOptions); - $this->assertContains(self::$keyName2, $rewrittenObject->info()['kmsKeyName']); + $this->assertStringContainsString(self::$keyName2, $rewrittenObject->info()['kmsKeyName']); $this->assertEquals(self::DATA, $rewrittenObject->downloadAsString()); } @@ -129,7 +132,7 @@ public function testRotatesCustomerSuppliedEncrpytionToKms() ]; $rewrittenObject = $object->rewrite(self::$bucket, $rewriteOptions); - $this->assertContains(self::$keyName1, $rewrittenObject->info()['kmsKeyName']); + $this->assertStringContainsString(self::$keyName1, $rewrittenObject->info()['kmsKeyName']); $this->assertEquals(self::DATA, $rewrittenObject->downloadAsString()); } diff --git a/Storage/tests/System/ManageBucketsTest.php b/Storage/tests/System/ManageBucketsTest.php index 22a30311ead7..21ae47b05bc1 100644 --- a/Storage/tests/System/ManageBucketsTest.php +++ b/Storage/tests/System/ManageBucketsTest.php @@ -19,6 +19,7 @@ use Google\Cloud\Core\Exception\BadRequestException; use Google\Cloud\Storage\Bucket; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -26,6 +27,8 @@ */ class ManageBucketsTest extends StorageTestCase { + use ExpectException; + public function testListsBuckets() { $foundBuckets = []; @@ -93,7 +96,7 @@ public function testUpdateBucket() public function testCreateBucketWithLifecycleDeleteRule(array $rule, $isError = false) { if ($isError) { - $this->setExpectedException(BadRequestException::class); + $this->expectException(BadRequestException::class); } $lifecycle = Bucket::lifecycle(); @@ -113,7 +116,7 @@ public function testCreateBucketWithLifecycleDeleteRule(array $rule, $isError = public function testUpdateBucketWithLifecycleDeleteRule(array $rule, $isError = false) { if ($isError) { - $this->setExpectedException(BadRequestException::class); + $this->expectException(BadRequestException::class); } $lifecycle = Bucket::lifecycle(); diff --git a/Storage/tests/System/ManageObjectsTest.php b/Storage/tests/System/ManageObjectsTest.php index bd36cc8d395d..3acaa7717e77 100644 --- a/Storage/tests/System/ManageObjectsTest.php +++ b/Storage/tests/System/ManageObjectsTest.php @@ -20,6 +20,8 @@ use Google\Cloud\Storage\StorageObject; use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\StreamInterface; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -27,6 +29,9 @@ */ class ManageObjectsTest extends StorageTestCase { + use AssertIsType; + use ExpectException; + const DATA = 'data'; public function testListsObjects() @@ -152,7 +157,7 @@ public function testDownloadsAsString() { $content = self::$object->downloadAsString(); - $this->assertInternalType('string', $content); + $this->assertIsString($content); } public function testDownloadsAsStream() @@ -193,12 +198,11 @@ public function testDownloadsPublicFileWithUnauthenticatedClient() $this->assertEquals(self::DATA, $actualData); } - /** - * @expectedException \Google\Cloud\Core\Exception\ServiceException - * @expectedExceptionCode 401 - */ public function testThrowsExceptionWhenDownloadsPrivateFileWithUnauthenticatedClient() { + $this->expectException('\Google\Cloud\Core\Exception\ServiceException'); + $this->expectExceptionCode(401); + $objectName = uniqid(self::TESTING_PREFIX); self::$bucket->upload(self::DATA, [ 'name' => $objectName, diff --git a/Storage/tests/System/PostPolicyTest.php b/Storage/tests/System/PostPolicyTest.php index 11e9884d7f2b..f9a33567c082 100644 --- a/Storage/tests/System/PostPolicyTest.php +++ b/Storage/tests/System/PostPolicyTest.php @@ -28,7 +28,7 @@ class PostPolicyTest extends StorageTestCase { private $guzzle; - public function setUp() + public function set_up() { $this->guzzle = new Client; } diff --git a/Storage/tests/System/RequesterPaysTest.php b/Storage/tests/System/RequesterPaysTest.php index 63d5e05f12d1..82979c9415be 100644 --- a/Storage/tests/System/RequesterPaysTest.php +++ b/Storage/tests/System/RequesterPaysTest.php @@ -23,6 +23,7 @@ use Google\Cloud\Storage\StorageClient; use Google\Cloud\Storage\StorageObject; use GuzzleHttp\Exception\ClientException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -30,6 +31,8 @@ */ class RequesterPaysTest extends StorageTestCase { + use ExpectException; + private static $requesterKeyFile; private static $requesterProject; private static $requesterEmail; @@ -46,9 +49,9 @@ class RequesterPaysTest extends StorageTestCase private static $topic; private static $notificationId; - public static function setupBeforeClass() + public static function set_up_before_class() { - parent::setupBeforeClass(); + parent::set_up_before_class(); $requesterKeyFilePath = getenv('GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH'); $ownerKeyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); @@ -146,10 +149,11 @@ public function testBucketSettings() /** * @dataProvider requesterPaysMethods - * @expectedException Google\Cloud\Core\Exception\BadRequestException */ public function testRequesterPaysMethodsWithoutUserProject(callable $call) { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $bucket = self::$requesterClient->bucket(self::$bucketName); $object = $bucket->object(self::$object1->name()); @@ -356,10 +360,11 @@ function (Bucket $bucket, StorageObject $object) { /** * @dataProvider uploadMethods - * @expectedException Google\Cloud\Core\Exception\GoogleException */ public function testUploadMethodsWithoutUserProject(callable $call) { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $bucket = self::$requesterClient->bucket(self::$bucketName); $call($bucket); } @@ -403,11 +408,10 @@ public function testDeleteNotification() $this->assertEquals(self::$requesterProject, $object->identity()['userProject']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testDeleteNotificationFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $bucket = self::$requesterClient->bucket(self::$bucketName); $bucket->notification(self::$notificationId)->delete(); } diff --git a/Storage/tests/System/SignedUrlTest.php b/Storage/tests/System/SignedUrlTest.php index a5c6e3b12408..0e0cc8d9e66c 100644 --- a/Storage/tests/System/SignedUrlTest.php +++ b/Storage/tests/System/SignedUrlTest.php @@ -20,6 +20,7 @@ use Google\Cloud\Core\Exception\NotFoundException; use Google\Cloud\Core\Timestamp; use GuzzleHttp\Client; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -27,11 +28,13 @@ */ class SignedUrlTest extends StorageTestCase { + use ExpectException; + const CONTENT = 'hello world!'; private $guzzle; - public function setUp() + public function set_up() { $this->guzzle = new Client; } @@ -107,10 +110,11 @@ public function testSignedUrlV4($objectName, array $urlOpts = []) /** * @dataProvider signingVersion - * @expectedException Google\Cloud\Core\Exception\NotFoundException */ public function testSignedUrlDelete($version) { + $this->expectException('Google\Cloud\Core\Exception\NotFoundException'); + $obj = $this->createFile(uniqid(self::TESTING_PREFIX)); $ts = (new \DateTime)->modify('+1 day'); diff --git a/Storage/tests/System/StorageTestCase.php b/Storage/tests/System/StorageTestCase.php index 6dc4aa30bd56..e8fd3bf67a8c 100644 --- a/Storage/tests/System/StorageTestCase.php +++ b/Storage/tests/System/StorageTestCase.php @@ -40,7 +40,7 @@ class StorageTestCase extends SystemTestCase protected static $mainBucketName; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Storage/tests/System/StreamWrapper/AppendTest.php b/Storage/tests/System/StreamWrapper/AppendTest.php index 2977df0fd3ad..59d9b355141e 100644 --- a/Storage/tests/System/StreamWrapper/AppendTest.php +++ b/Storage/tests/System/StreamWrapper/AppendTest.php @@ -30,13 +30,13 @@ class AppendTest extends StreamWrapperTestCase private $fileUrl; private $tailFileUrl; - public function setUp() + public function set_up() { $this->fileUrl = self::generateUrl(self::$fileName); $this->tailFileUrl = $this->fileUrl . StreamWrapper::TAIL_NAME_SUFFIX; } - public static function tearDownAfterCLass() + public static function tear_down_after_class() { $url = static::generateUrl(self::$fileName); unlink($url); diff --git a/Storage/tests/System/StreamWrapper/DirectoryTest.php b/Storage/tests/System/StreamWrapper/DirectoryTest.php index 8380552dc0c1..7d0b7d80d6b5 100644 --- a/Storage/tests/System/StreamWrapper/DirectoryTest.php +++ b/Storage/tests/System/StreamWrapper/DirectoryTest.php @@ -36,9 +36,9 @@ class DirectoryTest extends StreamWrapperTestCase 'bar/', ]; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); // create file in folder foreach (self::$createObjects as $name) { @@ -46,13 +46,13 @@ public static function setUpBeforeClass() } } - public static function tearDownAfterClass() + public static function tear_down_after_class() { foreach (self::$createObjects as $name) { self::$bucket->object($name)->delete(); } - parent::tearDownAfterClass(); + parent::tear_down_after_class(); } public function testMkDir() diff --git a/Storage/tests/System/StreamWrapper/FlushTest.php b/Storage/tests/System/StreamWrapper/FlushTest.php index 21c171228c7e..36830d8dcf65 100644 --- a/Storage/tests/System/StreamWrapper/FlushTest.php +++ b/Storage/tests/System/StreamWrapper/FlushTest.php @@ -33,7 +33,7 @@ class FlushTest extends StreamWrapperTestCase private $binFileUrl; private $tailBinFileUrl; - public function setUp() + public function set_up() { $this->fileUrl = self::generateUrl(self::$fileName); $this->tailFileUrl = $this->fileUrl . StreamWrapper::TAIL_NAME_SUFFIX; @@ -42,7 +42,7 @@ public function setUp() unlink($this->fileUrl); } - public function tearDown() + public function tear_down() { unlink($this->fileUrl); unlink($this->tailFileUrl); diff --git a/Storage/tests/System/StreamWrapper/ImageTest.php b/Storage/tests/System/StreamWrapper/ImageTest.php index f3e378173c67..b7b582716f9e 100644 --- a/Storage/tests/System/StreamWrapper/ImageTest.php +++ b/Storage/tests/System/StreamWrapper/ImageTest.php @@ -27,9 +27,9 @@ class ImageTest extends StreamWrapperTestCase const TEST_IMAGE_WITH_EXIF = 'https://storage.googleapis.com/cloud-php-testdata/fujifilm-dx10.jpg'; const TEST_IMAGE = 'https://storage.googleapis.com/cloud-php-testdata/screenshot.png'; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); // must get contents because we can't pass an fopen stream from the https stream wrapper // because it's not seekable diff --git a/Storage/tests/System/StreamWrapper/ReadTest.php b/Storage/tests/System/StreamWrapper/ReadTest.php index 73b12f257ac1..4733e4dac811 100644 --- a/Storage/tests/System/StreamWrapper/ReadTest.php +++ b/Storage/tests/System/StreamWrapper/ReadTest.php @@ -26,7 +26,7 @@ class ReadTest extends StreamWrapperTestCase { private $file; - public function setUp() + public function set_up() { $this->file = self::generateUrl(self::$object->name()); } diff --git a/Storage/tests/System/StreamWrapper/RenameTest.php b/Storage/tests/System/StreamWrapper/RenameTest.php index 11404bb7719b..b3cc83692367 100644 --- a/Storage/tests/System/StreamWrapper/RenameTest.php +++ b/Storage/tests/System/StreamWrapper/RenameTest.php @@ -27,9 +27,9 @@ class RenameTest extends StreamWrapperTestCase const TEST_FILE = 'some_folder/foo.txt'; const NEW_TEST_FILE = 'some_folder/bar.txt'; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); // create file in folder self::$bucket->upload('somedata', ['name' => self::TEST_FILE]); diff --git a/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php b/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php index 19332034e4ee..edacfc291bbc 100644 --- a/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php +++ b/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php @@ -26,16 +26,16 @@ */ class StreamWrapperTestCase extends StorageTestCase { - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$client->registerStreamWrapper(); } - public static function tearDownAfterClass() + public static function tear_down_after_class() { self::$client->unregisterStreamWrapper(); - parent::tearDownAfterClass(); + parent::tear_down_after_class(); } protected static function generateUrl($file, Bucket $bucket = null) diff --git a/Storage/tests/System/StreamWrapper/UrlStatTest.php b/Storage/tests/System/StreamWrapper/UrlStatTest.php index cc7d147e35b5..4557bb35504e 100644 --- a/Storage/tests/System/StreamWrapper/UrlStatTest.php +++ b/Storage/tests/System/StreamWrapper/UrlStatTest.php @@ -27,9 +27,9 @@ class UrlStatTest extends StreamWrapperTestCase protected static $fileUrl; protected static $dirUrl; - public static function setUpBeforeClass() + public static function set_up_before_class() { - parent::setUpBeforeClass(); + parent::set_up_before_class(); self::$fileUrl = self::generateUrl(self::$object->name()); self::$dirUrl = self::generateUrl('some_folder/'); mkdir(self::$dirUrl); diff --git a/Storage/tests/System/StreamWrapper/WriteTest.php b/Storage/tests/System/StreamWrapper/WriteTest.php index 4383a26ed162..6aaebd7a5b4f 100644 --- a/Storage/tests/System/StreamWrapper/WriteTest.php +++ b/Storage/tests/System/StreamWrapper/WriteTest.php @@ -26,13 +26,13 @@ class WriteTest extends StreamWrapperTestCase { private $fileUrl; - public function setUp() + public function set_up() { $this->fileUrl = self::generateUrl('output.txt'); unlink($this->fileUrl); } - public function tearDown() + public function tear_down() { unlink($this->fileUrl); } diff --git a/Storage/tests/System/UploadObjectsTest.php b/Storage/tests/System/UploadObjectsTest.php index 735756aaa251..a96b1a63e708 100644 --- a/Storage/tests/System/UploadObjectsTest.php +++ b/Storage/tests/System/UploadObjectsTest.php @@ -19,6 +19,7 @@ use Google\CRC32\CRC32; use GuzzleHttp\Psr7\Utils; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -26,6 +27,8 @@ */ class UploadObjectsTest extends StorageTestCase { + use ExpectException; + public function testUploadsObjectFromStringWithMetadata() { $data = 'somedata'; @@ -126,11 +129,10 @@ public function onStoredFileChunk($storedBytes) } } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testCrc32cChecksumFails() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + $path = __DIR__ . '/data/5mb.txt'; $crc32c = CRC32::create(CRC32::CASTAGNOLI); diff --git a/Storage/tests/Unit/AclTest.php b/Storage/tests/Unit/AclTest.php index 0ceeb54af9df..4c2a4144c6a9 100644 --- a/Storage/tests/Unit/AclTest.php +++ b/Storage/tests/Unit/AclTest.php @@ -20,25 +20,27 @@ use Google\Cloud\Storage\Acl; use Google\Cloud\Storage\Connection\ConnectionInterface; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage */ class AclTest extends TestCase { + use ExpectException; + public $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } - /** - * @expectedException InvalidArgumentException - */ public function testThrowsExceptionWithInvalidType() { + $this->expectException('InvalidArgumentException'); + $acl = new Acl($this->connection->reveal(), 'nope', ['bucket' => 'bucket']); } diff --git a/Storage/tests/Unit/BucketTest.php b/Storage/tests/Unit/BucketTest.php index c05bdb198768..1fcd590edfb7 100644 --- a/Storage/tests/Unit/BucketTest.php +++ b/Storage/tests/Unit/BucketTest.php @@ -37,14 +37,17 @@ use Google\Cloud\Storage\StorageObject; use GuzzleHttp\Promise; use GuzzleHttp\Promise\PromiseInterface; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage */ class BucketTest extends TestCase { + use ExpectException; + const TOPIC_NAME = 'my-topic'; const BUCKET_NAME = 'my-bucket'; const PROJECT_ID = 'my-project'; @@ -53,7 +56,7 @@ class BucketTest extends TestCase private $connection; private $resumableUploader; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->resumableUploader = $this->prophesize(ResumableUploader::class); @@ -148,11 +151,10 @@ public function testUploadAsyncData() ); } - /** - * @expectedException InvalidArgumentException - */ public function testUploadDataAsStringWithNoName() { + $this->expectException('InvalidArgumentException'); + $bucket = $this->getBucket(); $bucket->upload('some more data'); @@ -169,11 +171,10 @@ public function testGetResumableUploader() ); } - /** - * @expectedException InvalidArgumentException - */ public function testGetResumableUploaderWithStringWithNoName() { + $this->expectException('InvalidArgumentException'); + $bucket = $this->getBucket(); $bucket->getResumableUploader('some more data'); @@ -249,21 +250,19 @@ public function testDelete() $this->assertNull($bucket->delete()); } - /** - * @expectedException \InvalidArgumentException - */ public function testComposeThrowsExceptionWithLessThanTwoSources() { + $this->expectException('\InvalidArgumentException'); + $bucket = $this->getBucket(); $bucket->compose(['file1.txt'], 'combined-files.txt'); } - /** - * @expectedException \InvalidArgumentException - */ public function testComposeThrowsExceptionWithUnknownContentType() { + $this->expectException('\InvalidArgumentException'); + $bucket = $this->getBucket(); $bucket->compose(['file1.txt', 'file2.txt'], 'combined-files.abc'); @@ -455,11 +454,10 @@ public function testIsWritableAccessDenied() $this->assertFalse($bucket->isWritable()); } - /** - * @expectedException Google\Cloud\Core\Exception\ServerException - */ public function testIsWritableServerException() { + $this->expectException('Google\Cloud\Core\Exception\ServerException'); + $this->connection->insertObject(Argument::any())->willReturn($this->resumableUploader); $this->resumableUploader->getResumeUri()->willThrow(new ServerException('maintainence')); $bucket = $this->getBucket(); @@ -508,21 +506,19 @@ public function testCreatesNotification($topic, $expectedTopic) $this->assertEquals(self::NOTIFICATION_ID, $notification->id()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage $topic may only be a string or instance of Google\Cloud\PubSub\Topic - */ public function testCreatesNotificationThrowsExceptionWithInvalidTopicType() { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('$topic may only be a string or instance of Google\Cloud\PubSub\Topic'); + $bucket = $this->getBucket(); $bucket->createNotification(9124); } - /** - * @expectedException \Google\Cloud\Core\Exception\GoogleException - */ public function testCreatesNotificationThrowsExceptionWithoutProjectId() { + $this->expectException('\Google\Cloud\Core\Exception\GoogleException'); + $bucket = $this->getBucket([], true, null); $bucket->createNotification(self::TOPIC_NAME); } @@ -567,11 +563,10 @@ public function testGetNotifications() $this->assertEquals($notificationID, $notifications[0]->id()); } - /** - * @expectedException BadMethodCallException - */ public function testLockRetentionPolicyThrowsExceptionWithoutMetageneration() { + $this->expectException('BadMethodCallException'); + $this->getBucket()->lockRetentionPolicy(); } diff --git a/Storage/tests/Unit/ConformanceTest.php b/Storage/tests/Unit/ConformanceTest.php index 704ce6908e4b..f0327b062173 100644 --- a/Storage/tests/Unit/ConformanceTest.php +++ b/Storage/tests/Unit/ConformanceTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Storage\Tests\Unit; use Google\Cloud\Storage\StorageClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group storage @@ -28,7 +28,7 @@ class ConformanceTest extends TestCase { private static $cases; - public static function setUpBeforeClass() + public static function set_up_before_class() { static $setup = false; if ($setup) { @@ -146,7 +146,7 @@ public function testPostPolicy(array $testdata) public function signedUrlConformanceCases() { - self::setUpBeforeClass(); + self::set_up_before_class(); // rekey with description for more useful error reporting. $out = []; @@ -168,7 +168,7 @@ public function signedUrlConformanceCases() public function postPolicyConformanceCases() { - self::setUpBeforeClass(); + self::set_up_before_class(); // rekey with description for more useful error reporting. $out = []; diff --git a/Storage/tests/Unit/Connection/RestTest.php b/Storage/tests/Unit/Connection/RestTest.php index f6a26d978599..aaa84a529d7d 100644 --- a/Storage/tests/Unit/Connection/RestTest.php +++ b/Storage/tests/Unit/Connection/RestTest.php @@ -30,7 +30,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Utils; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; @@ -51,7 +51,7 @@ class RestTest extends TestCase 'userProject' => 'myProject' ]; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Storage/tests/Unit/CreatedHmacKeyTest.php b/Storage/tests/Unit/CreatedHmacKeyTest.php index 89f848facd40..3ef496a13f77 100644 --- a/Storage/tests/Unit/CreatedHmacKeyTest.php +++ b/Storage/tests/Unit/CreatedHmacKeyTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Storage\CreatedHmacKey; use Google\Cloud\Storage\HmacKey; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group storage @@ -32,7 +32,7 @@ class CreatedHmacKeyTest extends TestCase private $createdKey; - public function setUp() + public function set_up() { $this->createdKey = new CreatedHmacKey( $this->prophesize(HmacKey::class)->reveal(), diff --git a/Storage/tests/Unit/EncryptionTraitTest.php b/Storage/tests/Unit/EncryptionTraitTest.php index a7764fe6ae62..d6a2234cf3d3 100644 --- a/Storage/tests/Unit/EncryptionTraitTest.php +++ b/Storage/tests/Unit/EncryptionTraitTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\KeyPairGenerateTrait; use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Storage\EncryptionTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group storage @@ -31,7 +31,7 @@ class EncryptionTraitTest extends TestCase private $impl; - public function setUp() + public function set_up() { $this->impl = TestHelpers::impl(EncryptionTrait::class); } diff --git a/Storage/tests/Unit/HmacKeyTest.php b/Storage/tests/Unit/HmacKeyTest.php index 9b8efd1ae34e..e719c81d2bd8 100644 --- a/Storage/tests/Unit/HmacKeyTest.php +++ b/Storage/tests/Unit/HmacKeyTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Storage\Connection\ConnectionInterface; use Google\Cloud\Storage\HmacKey; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -39,7 +39,7 @@ class HmacKeyTest extends TestCase 'accessId' => 'foo' ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->key = TestHelpers::stub(HmacKey::class, [ diff --git a/Storage/tests/Unit/LifecycleTest.php b/Storage/tests/Unit/LifecycleTest.php index 7fb710fc9c4f..0c06a3086d31 100644 --- a/Storage/tests/Unit/LifecycleTest.php +++ b/Storage/tests/Unit/LifecycleTest.php @@ -18,7 +18,8 @@ namespace Google\Cloud\Storage\Tests\Unit; use Google\Cloud\Storage\Lifecycle; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -26,12 +27,14 @@ */ class LifecycleTest extends TestCase { + use ExpectException; + private $lifecycle; private static $condition = [ 'age' => 50 ]; - public function setUp() + public function set_up() { $this->lifecycle = new Lifecycle; } @@ -136,11 +139,10 @@ public function testClearRulesWithCallable() ); } - /** - * @expectedException \InvalidArgumentException - */ public function testClearRulesThrowsExceptionWithInvalidType() { + $this->expectException('\InvalidArgumentException'); + $this->lifecycle ->clearRules(123); } diff --git a/Storage/tests/Unit/NotificationTest.php b/Storage/tests/Unit/NotificationTest.php index 8856680c8fbe..ded2eb2825ff 100644 --- a/Storage/tests/Unit/NotificationTest.php +++ b/Storage/tests/Unit/NotificationTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Storage\Connection\ConnectionInterface; use Google\Cloud\Storage\Notification; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group storage @@ -38,7 +38,7 @@ class NotificationTest extends TestCase 'kind' => 'storage#notification' ]; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } diff --git a/Storage/tests/Unit/RequesterPaysTest.php b/Storage/tests/Unit/RequesterPaysTest.php index 16d9cbd4b377..1e8f29c1a634 100644 --- a/Storage/tests/Unit/RequesterPaysTest.php +++ b/Storage/tests/Unit/RequesterPaysTest.php @@ -22,7 +22,7 @@ use Google\Cloud\Core\Upload\AbstractUploader; use Google\Cloud\Storage\Connection\Rest; use Google\Cloud\Storage\StorageClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -41,7 +41,7 @@ class RequesterPaysTest extends TestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = new Rest(['projectId' => self::PROJECT]); $this->client = TestHelpers::stub( diff --git a/Storage/tests/Unit/SigningHelperTest.php b/Storage/tests/Unit/SigningHelperTest.php index eb3ba453a388..5298842841d0 100644 --- a/Storage/tests/Unit/SigningHelperTest.php +++ b/Storage/tests/Unit/SigningHelperTest.php @@ -24,8 +24,10 @@ use Google\Cloud\Core\Timestamp; use Google\Cloud\Storage\Connection\Rest; use Google\Cloud\Storage\SigningHelper; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group storage @@ -34,6 +36,9 @@ */ class SigningHelperTest extends TestCase { + use AssertStringContains; + use ExpectException; + const CLIENT_EMAIL = 'test@test.iam.gserviceaccount.com'; const BUCKET = 'test-bucket'; const OBJECT = 'test-object'; @@ -41,7 +46,7 @@ class SigningHelperTest extends TestCase private $helper; - public function setUp() + public function set_up() { $this->helper = TestHelpers::stub(SigningHelperStub::class); } @@ -259,9 +264,9 @@ public function testV4SignCanonicalRequestAndBucketBoundHostname() $this->assertEquals($expectedHeaders, $query['X-Goog-SignedHeaders']); $headers = explode("\n", $request[3]); - $this->assertContains('content-md5:' . $contentMd5, $headers); - $this->assertContains('content-type:' . $contentType, $headers); - $this->assertContains('host:' . $bucketBoundHostname, $headers); + $this->assertStringContainsString('content-md5:' . $contentMd5, $headers); + $this->assertStringContainsString('content-type:' . $contentType, $headers); + $this->assertStringContainsString('host:' . $bucketBoundHostname, $headers); $this->assertEquals($expectedHeaders, $request[4]); $this->assertEquals('UNSIGNED-PAYLOAD', $request[5]); @@ -410,11 +415,10 @@ public function testV4SignCanonicalRequestSaveAsName() ); } - /** - * @expectedException InvalidArgumentException - */ public function testV4SignInvalidExpiration() { + $this->expectException('InvalidArgumentException'); + $expires = (new \DateTime)->modify('+20 days'); $this->helper->v4Sign( $this->mockConnection($this->createCredentialsMock()->reveal()), @@ -468,11 +472,12 @@ public function expirations() } /** - * @expectedException InvalidArgumentException * @dataProvider urlMethods */ public function testInvalidExpiration($method) { + $this->expectException('InvalidArgumentException'); + $this->helper->$method( $this->mockConnection($this->createCredentialsMock()->reveal()), 'foobar', @@ -496,13 +501,7 @@ public function urlMethods() public function testNormalizeOptions(array $options, array $expected = null, $exception = null) { if ($exception) { - if (method_exists($this, 'setExpectedException')) { - $expectation = 'setExpectedException'; - } else { - $expectation = 'expectException'; - } - - $this->$expectation($exception); + $this->expectException($exception); } $res = $this->helper->proxyPrivateMethodCall('normalizeOptions', [$options]); @@ -542,11 +541,12 @@ public function options() } /** - * @expectedException InvalidArgumentException * @dataProvider invalidTimestamps */ public function testNormalizeOptionsInvalidTimestamps($timestamp) { + $this->expectException('InvalidArgumentException'); + $this->helper->proxyPrivateMethodCall('normalizeOptions', [ ['timestamp' => $timestamp] ]); @@ -600,10 +600,11 @@ public function headers() /** * @dataProvider v2InvalidHeaders - * @expectedException InvalidArgumentException */ public function testV2InvalidHeaders($header) { + $this->expectException('InvalidArgumentException'); + $this->helper->v2Sign( $this->mockConnection($this->prophesize(SignBlobInterface::class)->reveal()), time() + 10, @@ -748,11 +749,10 @@ public function keyfiles() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testGetSigningCredentialsInvalidKeyfilePath() { + $this->expectException('\InvalidArgumentException'); + $conn = $this->mockConnection(); $res = $this->helper->proxyPrivateMethodCall('getSigningCredentials', [ diff --git a/Storage/tests/Unit/StorageClientTest.php b/Storage/tests/Unit/StorageClientTest.php index 70df59ffeb71..2a566d3e709e 100644 --- a/Storage/tests/Unit/StorageClientTest.php +++ b/Storage/tests/Unit/StorageClientTest.php @@ -28,7 +28,8 @@ use Google\Cloud\Storage\StorageClient; use Google\Cloud\Storage\StreamWrapper; use GuzzleHttp\Psr7\Utils; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Prophecy\Argument; /** @@ -37,10 +38,12 @@ */ class StorageClientTest extends TestCase { + use ExpectException; + const PROJECT = 'my-project'; public $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->client = TestHelpers::stub(StorageClient::class, [['projectId' => self::PROJECT]]); @@ -238,11 +241,12 @@ public function testCreateHmacKey() } /** - * @expectedException Google\Cloud\Core\Exception\GoogleException * @dataProvider requiresProjectIdMethods */ public function testMethodsFailWithoutProjectId($method, array $args = []) { + $this->expectException('Google\Cloud\Core\Exception\GoogleException'); + $client = TestHelpers::stub(StorageClientStub::class, [], ['projectId']); $client->___setProperty('projectId', null); diff --git a/Storage/tests/Unit/StorageObjectTest.php b/Storage/tests/Unit/StorageObjectTest.php index ff0d583776de..3b856274e790 100644 --- a/Storage/tests/Unit/StorageObjectTest.php +++ b/Storage/tests/Unit/StorageObjectTest.php @@ -32,12 +32,13 @@ use GuzzleHttp\Promise; use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Psr7\Utils; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group storage @@ -45,6 +46,7 @@ */ class StorageObjectTest extends TestCase { + use ExpectException; use KeyPairGenerateTrait; const TIMESTAMP = '2025-01-01'; @@ -57,7 +59,7 @@ class StorageObjectTest extends TestCase private $key; private $kf; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(Rest::class); $this->key = $this->getKeyPair(); @@ -207,11 +209,10 @@ public function testCopyObjectWithNewName() $this->assertEquals($destinationObject, $copiedObject->info()['name']); } - /** - * @expectedException \InvalidArgumentException - */ public function testCopyObjectThrowsExceptionWithInvalidType() { + $this->expectException('\InvalidArgumentException'); + $object = new StorageObject($this->connection->reveal(), 'object.txt.', self::BUCKET); $copiedObject = $object->copy($object); } @@ -313,11 +314,10 @@ public function testRewriteObjectWithNewName() $this->assertEquals($destinationObject, $rewrittenObject->info()['name']); } - /** - * @expectedException \InvalidArgumentException - */ public function testRewriteObjectThrowsExceptionWithInvalidType() { + $this->expectException('\InvalidArgumentException'); + $object = new StorageObject($this->connection->reveal(), 'object.txt.', self::BUCKET); $copiedObject = $object->rewrite($object); } @@ -675,11 +675,11 @@ public function testSignedUrlVersions($version, $method) } /** - * @expectedException InvalidArgumentException * @group storage-signed-url */ public function testInvalidSigningVersion() { + $this->expectException('InvalidArgumentException'); $object = $this->getStorageObjectForSigning(); $object->signedUrl(time()+1, [ 'version' => uniqid() @@ -730,11 +730,11 @@ public function signedUrlKeyfiles() } /** - * @expectedException InvalidArgumentException * @group storage-signed-url */ public function testSignedUrlInvalidKeyFilePath() { + $this->expectException('InvalidArgumentException'); $object = $this->getStorageObjectForSigning(); $object->signedUrl(time(), [ 'keyFilePath' => __DIR__ . '/foo/bar/json.json' @@ -742,11 +742,11 @@ public function testSignedUrlInvalidKeyFilePath() } /** - * @expectedException InvalidArgumentException * @group storage-signed-url */ public function testSignedUrlInvalidKeyFileData() { + $this->expectException('InvalidArgumentException'); $file = tmpfile(); $path = stream_get_meta_data($file)['uri']; fwrite($file, '{'); diff --git a/Storage/tests/Unit/StreamWrapperTest.php b/Storage/tests/Unit/StreamWrapperTest.php index 16ef17cc0346..5b62c249a0f8 100644 --- a/Storage/tests/Unit/StreamWrapperTest.php +++ b/Storage/tests/Unit/StreamWrapperTest.php @@ -25,7 +25,9 @@ use Google\Cloud\Storage\StreamWrapper; use GuzzleHttp\Psr7\BufferStream; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; /** * @group storage @@ -33,14 +35,15 @@ */ class StreamWrapperTest extends TestCase { + use ExpectException; + use ExpectPHPException; + private $originalDefaultContext; private $connection; - public function setUp() + public function set_up() { - parent::setUp(); - $this->client = $this->prophesize(StorageClient::class); $this->bucket = $this->prophesize(Bucket::class); $this->client->bucket('my_bucket')->willReturn($this->bucket->reveal()); @@ -48,11 +51,9 @@ public function setUp() StreamWrapper::register($this->client->reveal()); } - public function tearDown() + public function tear_down() { StreamWrapper::unregister(); - - parent::tearDown(); } /** @@ -205,10 +206,11 @@ public function testStat() /** * @group storageInfo - * @expectedException PHPUnit_Framework_Error_Warning */ public function testStatOnNonExistentFile() { + $this->expectWarning(); + $object = $this->prophesize(StorageObject::class); $object->info()->willThrow(NotFoundException::class); $this->bucket->object('non-existent/file.txt') diff --git a/StorageTransfer/composer.json b/StorageTransfer/composer.json index e7ece4434a69..84a378760c77 100644 --- a/StorageTransfer/composer.json +++ b/StorageTransfer/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Talent/composer.json b/Talent/composer.json index c06f1bd2f56b..13ae9d3721b3 100644 --- a/Talent/composer.json +++ b/Talent/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Tasks/composer.json b/Tasks/composer.json index 06ab31ef3186..092b7786c411 100644 --- a/Tasks/composer.json +++ b/Tasks/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/TextToSpeech/composer.json b/TextToSpeech/composer.json index e26df581d95e..90babbaadf2b 100644 --- a/TextToSpeech/composer.json +++ b/TextToSpeech/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/Tpu/composer.json b/Tpu/composer.json index eab187000f77..7a72f6f3aac6 100644 --- a/Tpu/composer.json +++ b/Tpu/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Trace/composer.json b/Trace/composer.json index cd84a4b67a37..c47c699e90ee 100644 --- a/Trace/composer.json +++ b/Trace/composer.json @@ -9,7 +9,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6" diff --git a/Trace/phpunit-snippets.xml.dist b/Trace/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Trace/phpunit-snippets.xml.dist +++ b/Trace/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Trace/tests/Snippet/SpanTest.php b/Trace/tests/Snippet/SpanTest.php index a0c047d9aee3..7d1e655cb20f 100644 --- a/Trace/tests/Snippet/SpanTest.php +++ b/Trace/tests/Snippet/SpanTest.php @@ -23,17 +23,20 @@ use Google\Cloud\Trace\MessageEvent; use Google\Cloud\Trace\Span; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; /** * @group trace */ class SpanTest extends SnippetTestCase { + use AssertionRenames; + const EXPECTED_TIMESTAMP_FORMAT = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z$/'; private $span; - public function setUp() + public function set_up() { $this->span = new Span('abcd1234', ['name' => 'span name']); } @@ -50,7 +53,7 @@ public function testSetStartTime() $snippet = $this->snippetFromMethod(Span::class, 'setStartTime'); $snippet->addLocal('span', $this->span); $res = $snippet->invoke('span'); - $this->assertRegExp(self::EXPECTED_TIMESTAMP_FORMAT, $res->returnVal()->startTime()); + $this->assertMatchesRegularExpression(self::EXPECTED_TIMESTAMP_FORMAT, $res->returnVal()->startTime()); } public function testStartTime() @@ -84,7 +87,7 @@ public function testSetEndTime() $snippet = $this->snippetFromMethod(Span::class, 'setEndTime'); $snippet->addLocal('span', $this->span); $res = $snippet->invoke('span'); - $this->assertRegExp(self::EXPECTED_TIMESTAMP_FORMAT, $res->returnVal()->endTime()); + $this->assertMatchesRegularExpression(self::EXPECTED_TIMESTAMP_FORMAT, $res->returnVal()->endTime()); } public function testSetEndTimeWithValue() diff --git a/Trace/tests/Snippet/TraceClientTest.php b/Trace/tests/Snippet/TraceClientTest.php index 03ce7e9b77e9..323ec8732bec 100644 --- a/Trace/tests/Snippet/TraceClientTest.php +++ b/Trace/tests/Snippet/TraceClientTest.php @@ -23,16 +23,19 @@ use Google\Cloud\Trace\Trace; use Google\Cloud\Trace\TraceClient; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; /** * @group trace */ class TraceClientTest extends SnippetTestCase { + use AssertionRenames; + private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(TraceClient::class); @@ -69,7 +72,7 @@ public function testTrace() $res = $snippet->invoke('trace'); $trace = $res->returnVal(); $this->assertInstanceOf(Trace::class, $trace); - $this->assertRegExp('/[0-9a-f]{32}/', $trace->traceId()); + $this->assertMatchesRegularExpression('/[0-9a-f]{32}/', $trace->traceId()); } public function testTraceWithTraceId() diff --git a/Trace/tests/Snippet/TraceTest.php b/Trace/tests/Snippet/TraceTest.php index 5e28de297751..d572c3084b94 100644 --- a/Trace/tests/Snippet/TraceTest.php +++ b/Trace/tests/Snippet/TraceTest.php @@ -21,15 +21,18 @@ use Google\Cloud\Trace\Span; use Google\Cloud\Trace\Trace; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group trace */ class TraceTest extends SnippetTestCase { + use AssertIsType; + private $trace; - public function setUp() + public function set_up() { $this->trace = new Trace('my-project-id', 'abcd1234'); } @@ -55,7 +58,7 @@ public function testSpans() $this->trace->setSpans([$this->trace->span(['name' => 'foo'])]); $snippet->addLocal('trace', $this->trace); $res = $snippet->invoke('spans'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } public function testSpan() diff --git a/Trace/tests/Unit/Connection/GrpcTest.php b/Trace/tests/Unit/Connection/GrpcTest.php index 3bb534a2fe7d..3a12f4dfcbca 100644 --- a/Trace/tests/Unit/Connection/GrpcTest.php +++ b/Trace/tests/Unit/Connection/GrpcTest.php @@ -24,7 +24,7 @@ use Google\ApiCore\Serializer; use Google\Cloud\Trace\V2\Span; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group trace @@ -37,7 +37,7 @@ class GrpcTest extends TestCase private $requestWrapper; private $successMessage; - public function setUp() + public function set_up() { $this->checkAndSkipGrpcTests(); diff --git a/Trace/tests/Unit/Connection/RestTest.php b/Trace/tests/Unit/Connection/RestTest.php index 9491eedcade7..28d90d9ab2d4 100644 --- a/Trace/tests/Unit/Connection/RestTest.php +++ b/Trace/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Trace\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Trace/tests/Unit/SpanTest.php b/Trace/tests/Unit/SpanTest.php index 34466d2c9dd4..2733add01fcd 100644 --- a/Trace/tests/Unit/SpanTest.php +++ b/Trace/tests/Unit/SpanTest.php @@ -19,12 +19,15 @@ use Google\Cloud\Trace\Span; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; /** * @group trace */ class SpanTest extends TestCase { + use AssertionRenames; + const EXPECTED_TIMESTAMP_FORMAT = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z$/'; const TRACE_ID = 'abcd1234'; @@ -33,7 +36,7 @@ public function testGeneratesDefaultSpanId() $span = new Span(self::TRACE_ID); $info = $span->info(); $this->assertArrayHasKey('spanId', $info); - $this->assertRegExp('/^[0-9a-f]{16}$/', $info['spanId']); + $this->assertMatchesRegularExpression('/^[0-9a-f]{16}$/', $info['spanId']); $this->assertEquals($info['spanId'], $span->spanId()); } @@ -42,7 +45,7 @@ public function testReadsSpanId() $span = new Span(self::TRACE_ID, ['spanId' => '1234']); $info = $span->info(); $this->assertArrayHasKey('spanId', $info); - $this->assertEquals('1234', $info['spanId']); + $this->assertEquals(1234, (int) $info['spanId']); } public function testReadsAttributes() @@ -102,7 +105,7 @@ public function testStartFormat() $span->setStartTime(); $info = $span->info(); $this->assertArrayHasKey('startTime', $info); - $this->assertRegExp(self::EXPECTED_TIMESTAMP_FORMAT, $info['startTime']); + $this->assertMatchesRegularExpression(self::EXPECTED_TIMESTAMP_FORMAT, $info['startTime']); } public function testFinishFormat() @@ -111,7 +114,7 @@ public function testFinishFormat() $span->setEndTime(); $info = $span->info(); $this->assertArrayHasKey('endTime', $info); - $this->assertRegExp(self::EXPECTED_TIMESTAMP_FORMAT, $info['endTime']); + $this->assertMatchesRegularExpression(self::EXPECTED_TIMESTAMP_FORMAT, $info['endTime']); } public function testIgnoresUnknownFields() diff --git a/Trace/tests/Unit/TimestampTraitTest.php b/Trace/tests/Unit/TimestampTraitTest.php index 98494820fd42..0592b2410c53 100644 --- a/Trace/tests/Unit/TimestampTraitTest.php +++ b/Trace/tests/Unit/TimestampTraitTest.php @@ -19,12 +19,15 @@ use Google\Cloud\Trace\TimestampTrait; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; /** * @group trace */ class TimestampTraitTest extends TestCase { + use AssertionRenames; + const EXPECTED_TIMESTAMP_FORMAT = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z$/'; /** @@ -34,7 +37,7 @@ public function testFormatDate($expected, $input) { $obj = new TestTimestampClass(); $obj->setTime($input); - $this->assertRegExp(self::EXPECTED_TIMESTAMP_FORMAT, $obj->time()); + $this->assertMatchesRegularExpression(self::EXPECTED_TIMESTAMP_FORMAT, $obj->time()); if ($expected) { $this->assertEquals($expected, $obj->time()); } diff --git a/Trace/tests/Unit/TraceClientTest.php b/Trace/tests/Unit/TraceClientTest.php index baccfacafd25..0f0a45f1f049 100644 --- a/Trace/tests/Unit/TraceClientTest.php +++ b/Trace/tests/Unit/TraceClientTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Trace\Connection\ConnectionInterface; use Google\Cloud\Trace\Trace; use Google\Cloud\Trace\TraceClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -32,7 +32,7 @@ class TraceClientTest extends TestCase private $client; private $connection; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(TraceClient::class, [ ['projectId' => 'project'] diff --git a/Trace/tests/Unit/TraceTest.php b/Trace/tests/Unit/TraceTest.php index 72a195bff611..b037c055db86 100644 --- a/Trace/tests/Unit/TraceTest.php +++ b/Trace/tests/Unit/TraceTest.php @@ -20,17 +20,20 @@ use Google\Cloud\Trace\Connection\ConnectionInterface; use Google\Cloud\Trace\Trace; use Google\Cloud\Trace\Span; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; /** * @group trace */ class TraceTest extends TestCase { + use AssertionRenames; + /** @var ConnectionInterface|ObjectProphecy */ public $connection; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); } @@ -59,7 +62,7 @@ public function testLoadFromArray() public function testGeneratesDefaultTraceId() { $trace = new Trace('myproject'); - $this->assertRegExp('/^[0-9a-f]{32}$/', $trace->traceId()); + $this->assertMatchesRegularExpression('/^[0-9a-f]{32}$/', $trace->traceId()); } public function testBuildsSpan() diff --git a/Translate/composer.json b/Translate/composer.json index 43085e106b35..162223227cc4 100644 --- a/Translate/composer.json +++ b/Translate/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6" diff --git a/Translate/phpunit-snippets.xml.dist b/Translate/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Translate/phpunit-snippets.xml.dist +++ b/Translate/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Translate/tests/Snippet/V2/TranslateClientTest.php b/Translate/tests/Snippet/V2/TranslateClientTest.php index a37574f83412..755854ace406 100644 --- a/Translate/tests/Snippet/V2/TranslateClientTest.php +++ b/Translate/tests/Snippet/V2/TranslateClientTest.php @@ -31,7 +31,7 @@ class TranslateClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(TranslateClient::class); diff --git a/Translate/tests/System/V2/TranslateTest.php b/Translate/tests/System/V2/TranslateTest.php index b051338b6a4a..3c107c1dc4e9 100644 --- a/Translate/tests/System/V2/TranslateTest.php +++ b/Translate/tests/System/V2/TranslateTest.php @@ -17,11 +17,19 @@ namespace Google\Cloud\Translate\Tests\System\V2; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; + /** * @group translate */ class TranslateTest extends TranslateTestCase { + use AssertIsType; + use AssertStringContains; + use ExpectException; + const INPUT_LANGUAGE = 'es'; const INPUT_STRING = '¿hola, como estas?'; const OUTPUT_STRING = 'Hello how are you doing?'; @@ -59,27 +67,24 @@ public function testTranslateModelBase() $this->assertEquals('base', $res['model']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateInvalidModel() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translate(self::INPUT_STRING, ['model' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateInvalidTarget() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translate(self::INPUT_STRING, ['target' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateInvalidSource() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translate(self::INPUT_STRING, ['source' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } @@ -116,27 +121,24 @@ public function testTranslateBatchModelBase() $this->assertEquals('base', $res[0]['model']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateBatchInvalidModel() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translateBatch([self::INPUT_STRING], ['model' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateBatchInvalidTarget() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translateBatch([self::INPUT_STRING], ['target' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } - /** - * @expectedException Google\Cloud\Core\Exception\BadRequestException - */ public function testTranslateBatchInvalidSource() { + $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); + self::$client->translateBatch([self::INPUT_STRING], ['source' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); } @@ -195,9 +197,9 @@ public function testDetectLanguages() $client = self::$client; $res = $client->languages(); - $this->assertInternalType('array', $res); - $this->assertContains('en', $res); - $this->assertContains('es', $res); + $this->assertIsArray($res); + $this->assertStringContainsString('en', $res); + $this->assertStringContainsString('es', $res); } public function testLocalizedLanguages() @@ -205,8 +207,8 @@ public function testLocalizedLanguages() $client = self::$client; $res = $client->localizedLanguages(); - $this->assertInternalType('array', $res); - $this->assertContains(['code' => 'es', 'name' => 'Spanish'], $res); - $this->assertContains(['code' => 'en', 'name' => 'English'], $res); + $this->assertIsArray($res); + $this->assertStringContainsString(['code' => 'es', 'name' => 'Spanish'], $res); + $this->assertStringContainsString(['code' => 'en', 'name' => 'English'], $res); } } diff --git a/Translate/tests/System/V2/TranslateTestCase.php b/Translate/tests/System/V2/TranslateTestCase.php index 5415daa7a0dc..86c29bd54e36 100644 --- a/Translate/tests/System/V2/TranslateTestCase.php +++ b/Translate/tests/System/V2/TranslateTestCase.php @@ -18,14 +18,14 @@ namespace Google\Cloud\Translate\Tests\System\V2; use Google\Cloud\Translate\TranslateClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class TranslateTestCase extends TestCase { protected static $hasSetUp = false; protected static $client; - public static function setupBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Translate/tests/Unit/V2/Connection/RestTest.php b/Translate/tests/Unit/V2/Connection/RestTest.php index 576926e3a8c4..9f661fecc9a6 100644 --- a/Translate/tests/Unit/V2/Connection/RestTest.php +++ b/Translate/tests/Unit/V2/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Translate\V2\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Translate/tests/Unit/V2/TranslateClientTest.php b/Translate/tests/Unit/V2/TranslateClientTest.php index 41fdf5f08224..ddd6c6714454 100644 --- a/Translate/tests/Unit/V2/TranslateClientTest.php +++ b/Translate/tests/Unit/V2/TranslateClientTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Translate\V2\Connection\ConnectionInterface; use Google\Cloud\Translate\V2\TranslateClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -32,7 +32,7 @@ class TranslateClientTest extends TestCase private $connection; private $key = 'test_key'; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(TranslateClient::class, [ ['key' => $this->key] diff --git a/VideoIntelligence/composer.json b/VideoIntelligence/composer.json index 50d5d92add5c..c3f5772add3f 100644 --- a/VideoIntelligence/composer.json +++ b/VideoIntelligence/composer.json @@ -7,7 +7,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "google/cloud-core": "^1.39", "phpdocumentor/reflection": "^3.0" }, diff --git a/VideoIntelligence/tests/System/V1/VideoIntelligenceServiceClientTest.php b/VideoIntelligence/tests/System/V1/VideoIntelligenceServiceClientTest.php index f78b339063e4..205e89dffda1 100644 --- a/VideoIntelligence/tests/System/V1/VideoIntelligenceServiceClientTest.php +++ b/VideoIntelligence/tests/System/V1/VideoIntelligenceServiceClientTest.php @@ -35,7 +35,7 @@ class VideoIntelligenceServiceClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::set_up_before_class(); return [ [self::$restClient], @@ -43,7 +43,7 @@ public function clientProvider() ]; } - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/VideoLiveStream/composer.json b/VideoLiveStream/composer.json index 2ffc6fd800fa..0204f1099073 100644 --- a/VideoLiveStream/composer.json +++ b/VideoLiveStream/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/VideoStitcher/composer.json b/VideoStitcher/composer.json index 82f8815fbf34..f8d625c4284f 100644 --- a/VideoStitcher/composer.json +++ b/VideoStitcher/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/VideoTranscoder/composer.json b/VideoTranscoder/composer.json index adfd85ba70b1..e6200f9471e0 100644 --- a/VideoTranscoder/composer.json +++ b/VideoTranscoder/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Vision/composer.json b/Vision/composer.json index fe514ed76c69..0d9f583453e4 100644 --- a/Vision/composer.json +++ b/Vision/composer.json @@ -8,7 +8,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", diff --git a/Vision/phpunit-snippets.xml.dist b/Vision/phpunit-snippets.xml.dist index b92fd83e3c1b..503ea958da40 100644 --- a/Vision/phpunit-snippets.xml.dist +++ b/Vision/phpunit-snippets.xml.dist @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/Vision/tests/Snippet/Annotation/CropHintTest.php b/Vision/tests/Snippet/Annotation/CropHintTest.php index 20dd858c1e77..0c1f639305d5 100644 --- a/Vision/tests/Snippet/Annotation/CropHintTest.php +++ b/Vision/tests/Snippet/Annotation/CropHintTest.php @@ -32,7 +32,7 @@ class CropHintTest extends SnippetTestCase private $info; private $crop; - public function setUp() + public function set_up() { $this->info = [ 'boundingPoly' => ['foo' => 'bar'], diff --git a/Vision/tests/Snippet/Annotation/DocumentTest.php b/Vision/tests/Snippet/Annotation/DocumentTest.php index 2413450c2540..18f46bb60fd6 100644 --- a/Vision/tests/Snippet/Annotation/DocumentTest.php +++ b/Vision/tests/Snippet/Annotation/DocumentTest.php @@ -32,7 +32,7 @@ class DocumentTest extends SnippetTestCase private $info; private $document; - public function setUp() + public function set_up() { $this->info = [ 'pages' => [['foo' => 'bar']], diff --git a/Vision/tests/Snippet/Annotation/EntityTest.php b/Vision/tests/Snippet/Annotation/EntityTest.php index 0d88525e7479..b39d58e401c6 100644 --- a/Vision/tests/Snippet/Annotation/EntityTest.php +++ b/Vision/tests/Snippet/Annotation/EntityTest.php @@ -32,7 +32,7 @@ class EntityTest extends SnippetTestCase private $entityData; private $entity; - public function setUp() + public function set_up() { $this->entityData = [ 'mid' => 'testMid', diff --git a/Vision/tests/Snippet/Annotation/Face/LandmarksTest.php b/Vision/tests/Snippet/Annotation/Face/LandmarksTest.php index 39b0e5fed76e..cb54b0ef6d46 100644 --- a/Vision/tests/Snippet/Annotation/Face/LandmarksTest.php +++ b/Vision/tests/Snippet/Annotation/Face/LandmarksTest.php @@ -33,7 +33,7 @@ class LandmarksTest extends SnippetTestCase private $landmarksData; private $landmarks; - public function setUp() + public function set_up() { $this->pos = [ 'x' => 1, diff --git a/Vision/tests/Snippet/Annotation/FaceTest.php b/Vision/tests/Snippet/Annotation/FaceTest.php index 380519db1fe4..786e4e34350d 100644 --- a/Vision/tests/Snippet/Annotation/FaceTest.php +++ b/Vision/tests/Snippet/Annotation/FaceTest.php @@ -32,7 +32,7 @@ class FaceTest extends SnippetTestCase private $faceData; private $face; - public function setUp() + public function set_up() { $this->faceData = [ 'landmarks' => [[]], diff --git a/Vision/tests/Snippet/Annotation/ImagePropertiesTest.php b/Vision/tests/Snippet/Annotation/ImagePropertiesTest.php index 687c213d8d63..65cba6e007c0 100644 --- a/Vision/tests/Snippet/Annotation/ImagePropertiesTest.php +++ b/Vision/tests/Snippet/Annotation/ImagePropertiesTest.php @@ -32,7 +32,7 @@ class ImagePropertiesTest extends SnippetTestCase private $propsData; private $props; - public function setUp() + public function set_up() { $this->propsData = ['dominantColors' => ['colors' => 'colorsTest']]; $this->props = new ImageProperties($this->propsData); diff --git a/Vision/tests/Snippet/Annotation/SafeSearchTest.php b/Vision/tests/Snippet/Annotation/SafeSearchTest.php index 35f8233b964b..288f1b1ea28c 100644 --- a/Vision/tests/Snippet/Annotation/SafeSearchTest.php +++ b/Vision/tests/Snippet/Annotation/SafeSearchTest.php @@ -32,7 +32,7 @@ class SafeSearchTest extends SnippetTestCase private $ssData; private $ss; - public function setUp() + public function set_up() { $this->ssData = [ 'adult' => 'VERY_LIKELY', diff --git a/Vision/tests/Snippet/Annotation/Web/WebEntityTest.php b/Vision/tests/Snippet/Annotation/Web/WebEntityTest.php index e02f14348c00..45e95d1a0b8d 100644 --- a/Vision/tests/Snippet/Annotation/Web/WebEntityTest.php +++ b/Vision/tests/Snippet/Annotation/Web/WebEntityTest.php @@ -32,7 +32,7 @@ class WebEntityTest extends SnippetTestCase private $info; private $entity; - public function setUp() + public function set_up() { $this->info = [ 'entityId' => 'foo', diff --git a/Vision/tests/Snippet/Annotation/Web/WebImageTest.php b/Vision/tests/Snippet/Annotation/Web/WebImageTest.php index f0ee93727170..0a2cf6009167 100644 --- a/Vision/tests/Snippet/Annotation/Web/WebImageTest.php +++ b/Vision/tests/Snippet/Annotation/Web/WebImageTest.php @@ -32,7 +32,7 @@ class WebImageTest extends SnippetTestCase private $info; private $image; - public function setUp() + public function set_up() { $this->info = [ 'url' => 'http://foo.bar/image.jpg', diff --git a/Vision/tests/Snippet/Annotation/Web/WebPageTest.php b/Vision/tests/Snippet/Annotation/Web/WebPageTest.php index 2d4156b2b1e2..9e230eeb3d5a 100644 --- a/Vision/tests/Snippet/Annotation/Web/WebPageTest.php +++ b/Vision/tests/Snippet/Annotation/Web/WebPageTest.php @@ -32,7 +32,7 @@ class WebPageTest extends SnippetTestCase private $info; private $image; - public function setUp() + public function set_up() { $this->info = [ 'url' => 'http://foo.bar/image.jpg', diff --git a/Vision/tests/Snippet/Annotation/WebTest.php b/Vision/tests/Snippet/Annotation/WebTest.php index 4730c550634d..6c15b16a74a0 100644 --- a/Vision/tests/Snippet/Annotation/WebTest.php +++ b/Vision/tests/Snippet/Annotation/WebTest.php @@ -35,7 +35,7 @@ class WebTest extends SnippetTestCase private $info; private $web; - public function setUp() + public function set_up() { $this->info = [ 'webEntities' => [ diff --git a/Vision/tests/Snippet/AnnotationTest.php b/Vision/tests/Snippet/AnnotationTest.php index 752c418fe6c3..ab9ad6989a06 100644 --- a/Vision/tests/Snippet/AnnotationTest.php +++ b/Vision/tests/Snippet/AnnotationTest.php @@ -30,12 +30,15 @@ use Google\Cloud\Vision\Connection\ConnectionInterface; use Google\Cloud\Vision\VisionClient; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group vision */ class AnnotationTest extends SnippetTestCase { + use AssertIsType; + public function testClass() { $snippet = $this->snippetFromClass(Annotation::class); @@ -202,6 +205,6 @@ public function testError() ])); $res = $snippet->invoke('error'); - $this->assertInternalType('array', $res->returnVal()); + $this->assertIsArray($res->returnVal()); } } diff --git a/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php b/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php index ba86281e0e83..a5f231c9ab90 100644 --- a/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php +++ b/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php @@ -32,11 +32,11 @@ */ class ImageAnnotatorClientTest extends SnippetTestCase { - /** @var ImageAnnotatorClient */ + /** @var ImageAnnotatorClient */ private $client; private $transport; - public function setUp() + public function set_up() { $this->transport = $this->prophesize(TransportInterface::class); $this->client = new ImageAnnotatorClient([ diff --git a/Vision/tests/Snippet/VisionClientTest.php b/Vision/tests/Snippet/VisionClientTest.php index cb20c7f0400c..d72dfbc29848 100644 --- a/Vision/tests/Snippet/VisionClientTest.php +++ b/Vision/tests/Snippet/VisionClientTest.php @@ -33,7 +33,7 @@ class VisionClientTest extends SnippetTestCase private $connection; private $client; - public function setUp() + public function set_up() { $this->connection = $this->prophesize(ConnectionInterface::class); $this->client = TestHelpers::stub(VisionClient::class); diff --git a/Vision/tests/System/AnnotationsTest.php b/Vision/tests/System/AnnotationsTest.php index 10360da0293b..65e19a50233c 100644 --- a/Vision/tests/System/AnnotationsTest.php +++ b/Vision/tests/System/AnnotationsTest.php @@ -29,15 +29,18 @@ use Google\Cloud\Vision\Annotation\Web\WebEntity; use Google\Cloud\Vision\Annotation\Web\WebImage; use Google\Cloud\Vision\Annotation\Web\WebPage; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group vision */ class AnnotationsTest extends VisionTestCase { + use AssertIsType; + private $client; - public function setUp() + public function set_up() { $this->client = parent::$vision; } @@ -74,12 +77,12 @@ public function testAnnotate() // Image Properties $this->assertInstanceOf(ImageProperties::class, $res->imageProperties()); - $this->assertInternalType('array', $res->imageProperties()->colors()); + $this->assertIsArray($res->imageProperties()->colors()); // Crop Hints $this->assertInstanceOf(CropHint::class, $res->cropHints()[0]); $this->assertArrayHasKey('vertices', $res->cropHints()[0]->boundingPoly()); - $this->assertInternalType('float', $res->cropHints()[0]->confidence()); + $this->assertIsFloat($res->cropHints()[0]->confidence()); $this->assertNotNull($res->cropHints()[0]->importanceFraction()); // Web Annotation diff --git a/Vision/tests/System/VisionTestCase.php b/Vision/tests/System/VisionTestCase.php index 06f89203b968..8bc79388b98b 100644 --- a/Vision/tests/System/VisionTestCase.php +++ b/Vision/tests/System/VisionTestCase.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\System; use Google\Cloud\Vision\VisionClient; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class VisionTestCase extends TestCase protected static $vision; private static $hasSetUp = false; - public static function setUpBeforeClass() + public static function set_up_before_class() { if (self::$hasSetUp) { return; diff --git a/Vision/tests/Unit/Annotation/CropHintTest.php b/Vision/tests/Unit/Annotation/CropHintTest.php index 41da3f006815..1ad5c822b90e 100644 --- a/Vision/tests/Unit/Annotation/CropHintTest.php +++ b/Vision/tests/Unit/Annotation/CropHintTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\Unit\Annotation; use Google\Cloud\Vision\Annotation\CropHint; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class CropHintTest extends TestCase private $info; private $hint; - public function setUp() + public function set_up() { $this->info = [ 'boundingPoly' => ['foo' => 'bar'], diff --git a/Vision/tests/Unit/Annotation/Face/LandmarksTest.php b/Vision/tests/Unit/Annotation/Face/LandmarksTest.php index 87cb3169e2b9..551e7e0cbb2a 100644 --- a/Vision/tests/Unit/Annotation/Face/LandmarksTest.php +++ b/Vision/tests/Unit/Annotation/Face/LandmarksTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Vision\Tests\Unit\Fixtures; use Google\Cloud\Vision\Annotation\Face\Landmarks; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -29,7 +29,7 @@ class LandmarksTest extends TestCase private $data; private $landmarks; - public function setUp() + public function set_up() { $this->data = json_decode(file_get_contents(Fixtures::FACE_LANDMARKS_FIXTURE()), true); $this->landmarks = new Landmarks($this->data); diff --git a/Vision/tests/Unit/Annotation/FaceTest.php b/Vision/tests/Unit/Annotation/FaceTest.php index 1a318b37c1c7..ce58e56153a6 100644 --- a/Vision/tests/Unit/Annotation/FaceTest.php +++ b/Vision/tests/Unit/Annotation/FaceTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Vision\Annotation\Face; use Google\Cloud\Vision\Annotation\Face\Landmarks; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class FaceTest extends TestCase { private $face; - public function setUp() + public function set_up() { $this->face = new Face([ 'landmarks' => [], diff --git a/Vision/tests/Unit/Annotation/LikelihoodTraitTest.php b/Vision/tests/Unit/Annotation/LikelihoodTraitTest.php index 1965df32edcb..cdf485795b84 100644 --- a/Vision/tests/Unit/Annotation/LikelihoodTraitTest.php +++ b/Vision/tests/Unit/Annotation/LikelihoodTraitTest.php @@ -20,16 +20,19 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Vision\Annotation\FeatureInterface; use Google\Cloud\Vision\Annotation\LikelihoodTrait; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group vision */ class LikelihoodTraitTest extends TestCase { + use ExpectException; + private $stub; - public function setUp() + public function set_up() { $this->stub = TestHelpers::impl(LikelihoodTrait::class); } @@ -60,11 +63,10 @@ public function likelihood() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testErr() { + $this->expectException('InvalidArgumentException'); + $this->stub->call('likelihood', ['foo', 'bar']); } } diff --git a/Vision/tests/Unit/Annotation/SafeSearchTest.php b/Vision/tests/Unit/Annotation/SafeSearchTest.php index 69c6de037008..69ff795a0932 100644 --- a/Vision/tests/Unit/Annotation/SafeSearchTest.php +++ b/Vision/tests/Unit/Annotation/SafeSearchTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\Unit\Annotation; use Google\Cloud\Vision\Annotation\SafeSearch; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -27,7 +27,7 @@ class SafeSearchTest extends TestCase { private $safeSearch; - public function setUp() + public function set_up() { $this->safeSearch = new SafeSearch([ 'adult' => 'VERY_LIKELY', diff --git a/Vision/tests/Unit/Annotation/Web/WebEntityTest.php b/Vision/tests/Unit/Annotation/Web/WebEntityTest.php index 53851f6d2cb1..3e37cb3a98a6 100644 --- a/Vision/tests/Unit/Annotation/Web/WebEntityTest.php +++ b/Vision/tests/Unit/Annotation/Web/WebEntityTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\Unit\Annotation\Web; use Google\Cloud\Vision\Annotation\Web\WebEntity; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class WebEntityTest extends TestCase private $info; private $entity; - public function setUp() + public function set_up() { $this->info = [ 'entityId' => 'foo', diff --git a/Vision/tests/Unit/Annotation/Web/WebImageTest.php b/Vision/tests/Unit/Annotation/Web/WebImageTest.php index 9d9b27b12f2a..9c36aad5b8c0 100644 --- a/Vision/tests/Unit/Annotation/Web/WebImageTest.php +++ b/Vision/tests/Unit/Annotation/Web/WebImageTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\Unit\Annotation\Web; use Google\Cloud\Vision\Annotation\Web\WebImage; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class WebImageTest extends TestCase private $info; private $image; - public function setUp() + public function set_up() { $this->info = [ 'url' => 'http://foo.bar/bat', diff --git a/Vision/tests/Unit/Annotation/Web/WebPageTest.php b/Vision/tests/Unit/Annotation/Web/WebPageTest.php index 5262d69f607b..c90a33c816cf 100644 --- a/Vision/tests/Unit/Annotation/Web/WebPageTest.php +++ b/Vision/tests/Unit/Annotation/Web/WebPageTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Vision\Tests\Unit\Annotation\Web; use Google\Cloud\Vision\Annotation\Web\WebPage; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -28,7 +28,7 @@ class WebPageTest extends TestCase private $info; private $image; - public function setUp() + public function set_up() { $this->info = [ 'url' => 'http://foo.bar/bat', diff --git a/Vision/tests/Unit/Annotation/WebTest.php b/Vision/tests/Unit/Annotation/WebTest.php index 92ed6a1b90b2..319df9a32f3d 100644 --- a/Vision/tests/Unit/Annotation/WebTest.php +++ b/Vision/tests/Unit/Annotation/WebTest.php @@ -21,7 +21,7 @@ use Google\Cloud\Vision\Annotation\Web\WebEntity; use Google\Cloud\Vision\Annotation\Web\WebImage; use Google\Cloud\Vision\Annotation\Web\WebPage; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -31,7 +31,7 @@ class WebTest extends TestCase private $info; private $annotation; - public function setUp() + public function set_up() { $this->info = [ 'webEntities' => [ diff --git a/Vision/tests/Unit/Connection/RestTest.php b/Vision/tests/Unit/Connection/RestTest.php index a8786f14a49e..190a322455f0 100644 --- a/Vision/tests/Unit/Connection/RestTest.php +++ b/Vision/tests/Unit/Connection/RestTest.php @@ -23,7 +23,7 @@ use Google\Cloud\Vision\Connection\Rest; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; @@ -35,7 +35,7 @@ class RestTest extends TestCase private $requestWrapper; private $successBody; - public function setUp() + public function set_up() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); $this->successBody = '{"canI":"kickIt"}'; diff --git a/Vision/tests/Unit/ImageTest.php b/Vision/tests/Unit/ImageTest.php index 85199688fe3a..f5d95e8dc575 100644 --- a/Vision/tests/Unit/ImageTest.php +++ b/Vision/tests/Unit/ImageTest.php @@ -20,12 +20,15 @@ use Google\Cloud\Storage\StorageClient; use Google\Cloud\Vision\Image; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group vision */ class ImageTest extends TestCase { + use ExpectException; + public function testWithString() { $bytes = file_get_contents(Fixtures::EIFFEL_TOWER_FIXTURE()); @@ -75,11 +78,10 @@ public function testWithExternalImage() $this->assertEquals($res['features'], [ ['type' => 'LANDMARK_DETECTION'] ]); } - /** - * @expectedException InvalidArgumentException - */ public function testWithInvalidType() { + $this->expectException('InvalidArgumentException'); + new Image([], ['landmarks']); } diff --git a/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php b/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php index 84a540e86a7e..0cb90f4f5a0e 100644 --- a/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php +++ b/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php @@ -33,7 +33,7 @@ use Google\Cloud\Vision\VisionHelpersTrait; use GuzzleHttp\Promise\FulfilledPromise; use Prophecy\Argument; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group vision @@ -47,7 +47,7 @@ class ImageAnnotatorClientExtensionTest extends TestCase private $client; private $transport; - public function setUp() + public function set_up() { $this->transport = $this->prophesize(TransportInterface::class); $this->client = new ImageAnnotatorClient([ diff --git a/Vision/tests/Unit/VisionClientTest.php b/Vision/tests/Unit/VisionClientTest.php index 59723a0bd5dd..8deaf9aa3662 100644 --- a/Vision/tests/Unit/VisionClientTest.php +++ b/Vision/tests/Unit/VisionClientTest.php @@ -22,19 +22,24 @@ use Google\Cloud\Vision\Connection\ConnectionInterface; use Google\Cloud\Vision\Image; use Google\Cloud\Vision\VisionClient; -use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; /** * @group vision */ class VisionClientTest extends TestCase { + use AssertIsType; + use ExpectException; + private $client; private $connection; - public function setUp() + public function set_up() { $this->client = TestHelpers::stub(VisionClient::class); $this->connection = $this->prophesize(ConnectionInterface::class); @@ -88,17 +93,16 @@ public function testAnnotateBatch() $res = $this->client->annotateBatch([$image]); - $this->assertInternalType('array', $res); + $this->assertIsArray($res); $this->assertInstanceOf(Annotation::class, $res[0]); $this->assertInstanceOf(Annotation::class, $res[1]); } - /** - * @expectedException InvalidArgumentException - */ public function testAnnotateBatchInvalidImageType() { + $this->expectException('InvalidArgumentException'); + $this->client->annotateBatch(['test']); } } diff --git a/Vision/tests/Unit/VisionHelpersTraitTest.php b/Vision/tests/Unit/VisionHelpersTraitTest.php index 220bd975ccd7..d0ea3fcacc72 100644 --- a/Vision/tests/Unit/VisionHelpersTraitTest.php +++ b/Vision/tests/Unit/VisionHelpersTraitTest.php @@ -28,19 +28,21 @@ use Google\Cloud\Vision\V1\ImageSource; use Google\Cloud\Vision\VisionHelpersTrait; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group vision */ class VisionHelpersTraitTest extends TestCase { + use ExpectException; use VisionHelpersTrait; private $implementation; - public function setUp() + public function set_up() { $this->implementation = TestHelpers::impl(VisionHelpersTrait::class); } @@ -125,10 +127,11 @@ public function createImageHelperDataProvider() /** * @dataProvider invalidCreateImageHelperDataProvider - * @expectedException InvalidArgumentException */ public function testInvalidCreateImageHelper($imageInput) { + $this->expectException('InvalidArgumentException'); + $this->implementation->call('createImageHelper', [ Image::class, ImageSource::class, diff --git a/VmMigration/composer.json b/VmMigration/composer.json index 7c21d14a42ab..633780315b4b 100644 --- a/VmMigration/composer.json +++ b/VmMigration/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.12.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/VpcAccess/composer.json b/VpcAccess/composer.json index d6a1df8ae6ff..cf0f79e25fe1 100644 --- a/VpcAccess/composer.json +++ b/VpcAccess/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/WebRisk/composer.json b/WebRisk/composer.json index 77ac3e4cc175..242f62865953 100644 --- a/WebRisk/composer.json +++ b/WebRisk/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/WebSecurityScanner/composer.json b/WebSecurityScanner/composer.json index add2471927f3..b9dd91bd2205 100644 --- a/WebSecurityScanner/composer.json +++ b/WebSecurityScanner/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/Workflows/composer.json b/Workflows/composer.json index f2cad803a39b..bf9fcb8a7c20 100644 --- a/Workflows/composer.json +++ b/Workflows/composer.json @@ -26,7 +26,8 @@ "google/gax": "^1.6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "phpdocumentor/reflection": "^3.0" }, "suggest": { diff --git a/composer.json b/composer.json index 8ca675f24c05..a624d5ae575f 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,8 @@ "google/crc32": "^0.1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", + "phpunit/phpunit": "^4.8|^5.0|^8.0", + "yoast/phpunit-polyfills": "^1.0", "squizlabs/php_codesniffer": "3.*", "phpdocumentor/reflection": "^3.0", "symfony/console": "^3.0", @@ -67,8 +68,7 @@ "google/cloud-tools": "^0.12.0", "opis/closure": "^3.0", "swaggest/json-schema": "^0.12.0", - "wikimedia/avro": "^1.9", - "monolog/monolog": "<2.3.0" + "wikimedia/avro": "^1.9" }, "replace": { "google/access-context-manager": "0.2.1", diff --git a/dev/src/AddComponent/templates/template-phpunit-snippets.xml.dist.txt b/dev/src/AddComponent/templates/template-phpunit-snippets.xml.dist.txt index b92fd83e3c1b..503ea958da40 100644 --- a/dev/src/AddComponent/templates/template-phpunit-snippets.xml.dist.txt +++ b/dev/src/AddComponent/templates/template-phpunit-snippets.xml.dist.txt @@ -2,7 +2,7 @@ + > tests/Snippet diff --git a/dev/src/DocGenerator/Parser/CodeParser.php b/dev/src/DocGenerator/Parser/CodeParser.php index 1e8f4d934eac..cb12fc95b3ed 100644 --- a/dev/src/DocGenerator/Parser/CodeParser.php +++ b/dev/src/DocGenerator/Parser/CodeParser.php @@ -335,7 +335,10 @@ private function buildDescriptionContent( } $reference = substr($reference, strlen($namespace)); $tagContent[] = $this->buildReference($reference); - printf('Manual fix applied (%s). Please fix the reference' . PHP_EOL, $reference); + $this->output->writeln( + sprintf('Manual fix applied (%s). Please fix the reference', $reference), + OutputInterface::VERBOSITY_DEBUG + ); } } elseif (strtolower($tag->getName()) === 'inheritdoc') { if ($element === null) { @@ -700,7 +703,10 @@ private function buildNestedParams( // START proto nested arg missing description workaround if (count($nestedParam) < 3 && !$isProto) { - $this->output->writeln('nested param is in an invalid format: '. $param); + $this->output->writeln( + 'nested param is in an invalid format: '. $param, + OutputInterface::VERBOSITY_DEBUG + ); } // END proto nested arg missing description workaround diff --git a/dev/tests/Unit/ComponentManagerTest.php b/dev/tests/Unit/ComponentManagerTest.php index c4e0483cb0c1..96e1c21fe6dd 100644 --- a/dev/tests/Unit/ComponentManagerTest.php +++ b/dev/tests/Unit/ComponentManagerTest.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Dev\ComponentManager; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * @group dev @@ -30,7 +30,7 @@ class ComponentManagerTest extends TestCase private $cm; - public function setUp() + public function set_up() { $this->cm = TestHelpers::stub(ComponentManager::class, [ self::ROOT_PATH diff --git a/dev/tests/Unit/Split/GitHubTest.php b/dev/tests/Unit/Split/GitHubTest.php index 24db2babe8ca..b918119353ab 100644 --- a/dev/tests/Unit/Split/GitHubTest.php +++ b/dev/tests/Unit/Split/GitHubTest.php @@ -23,7 +23,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -42,7 +42,7 @@ class GitHubTest extends TestCase private $github; private $exception; - public function setUp() + public function set_up() { if (PHP_VERSION_ID < 50600) { $this->markTestSkipped("This test only runs on PHP 5.6+"); diff --git a/dev/tests/Unit/Split/ReleaseNotesTest.php b/dev/tests/Unit/Split/ReleaseNotesTest.php index fc957bef0eb3..def77ddd51bf 100644 --- a/dev/tests/Unit/Split/ReleaseNotesTest.php +++ b/dev/tests/Unit/Split/ReleaseNotesTest.php @@ -18,7 +18,8 @@ namespace Google\Cloud\Dev\Tests\Unit; use Google\Cloud\Dev\Split\ReleaseNotes; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group dev @@ -26,9 +27,11 @@ */ class ReleaseNotesTest extends TestCase { + use AssertStringContains; + private $releaseNotes; - public function setUp() + public function set_up() { $this->releaseNotes = new ReleaseNotes( file_get_contents(__DIR__ . '/../../fixtures/split/release-notes.md') @@ -39,7 +42,7 @@ public function testGet() { $note = $this->releaseNotes->get('cloud-automl'); $this->assertNotNull($note); - $this->assertContains("Miscellaneous Chores", $note); + $this->assertStringContainsString("Miscellaneous Chores", $note); $this->assertNull($this->releaseNotes->get('cloud-foobar')); } diff --git a/dev/tests/Unit/Split/SplitInstallTest.php b/dev/tests/Unit/Split/SplitInstallTest.php index c22d42b4bea8..09b256beb458 100644 --- a/dev/tests/Unit/Split/SplitInstallTest.php +++ b/dev/tests/Unit/Split/SplitInstallTest.php @@ -20,7 +20,8 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Dev\Split\RunShell; use Google\Cloud\Dev\Split\SplitInstall; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * @group dev @@ -28,13 +29,15 @@ */ class SplitInstallTest extends TestCase { + use ExpectException; + const ROOT_PATH = '/foo/www'; const INSTALL_PATH = '/foo/bar/bin'; private $shell; private $install; - public function setUp() + public function set_up() { $this->shell = $this->prophesize(RunShell::class); $this->install = TestHelpers::stub(SplitInstallStub::class, [ @@ -69,12 +72,11 @@ public function testInstallFromSourceAlreadyInstalled() ], $res); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Splitsh compile failed with output: Uh oh - */ public function testInstallFromSourceFails() { + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Splitsh compile failed with output: Uh oh'); + $cmd = self::ROOT_PATH . '/' . SplitInstall::COMPILE_SCRIPT . ' ' . self::INSTALL_PATH; $this->shell->execute($cmd)->shouldBeCalled()->willReturn([false, ['Uh oh']]); diff --git a/dev/tests/Unit/Split/SplitTest.php b/dev/tests/Unit/Split/SplitTest.php index 72b59693084b..a3309672dd3b 100644 --- a/dev/tests/Unit/Split/SplitTest.php +++ b/dev/tests/Unit/Split/SplitTest.php @@ -20,7 +20,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Dev\Split\RunShell; use Google\Cloud\Dev\Split\Split; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; use Prophecy\Argument; /** @@ -32,7 +32,7 @@ class SplitTest extends TestCase private $shell; private $split; - public function setUp() + public function set_up() { $this->shell = $this->prophesize(RunShell::class); $this->split = TestHelpers::stub(Split::class, [ diff --git a/phpcs-ruleset.xml b/phpcs-ruleset.xml index e5417af46498..b355ede38fad 100644 --- a/phpcs-ruleset.xml +++ b/phpcs-ruleset.xml @@ -4,6 +4,8 @@ Storage/src/StreamWrapper.php Speech/tests/Unit/HttpStreamWrapper.php + */tests/*/*Test.php + */tests/*/*TestCase.php Core/src/Testing/Lock/MockValues.php diff --git a/phpunit-php5-snippets.xml.dist b/phpunit-php5-snippets.xml.dist index 626eb548c93d..c487c712b16f 100644 --- a/phpunit-php5-snippets.xml.dist +++ b/phpunit-php5-snippets.xml.dist @@ -2,7 +2,6 @@ diff --git a/phpunit-php5.xml.dist b/phpunit-php5.xml.dist index 2b9a93b152cc..bea338c9d719 100644 --- a/phpunit-php5.xml.dist +++ b/phpunit-php5.xml.dist @@ -23,10 +23,10 @@ + + + - - - diff --git a/phpunit-snippets.xml.dist b/phpunit-snippets.xml.dist index 5d8acdcddf34..b72e293cdeab 100644 --- a/phpunit-snippets.xml.dist +++ b/phpunit-snippets.xml.dist @@ -2,7 +2,6 @@ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0660d4665a7f..08b89c3d9ef7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,28 @@ - + + + + */src + src + + + */src/V[!a-zA-Z]* + */src/*/V[!a-zA-Z]* + */src/*/*/V[!a-zA-Z]* + Core/src/Testing + dev + + - + */tests/Unit ./tests/Unit - - - */src - src - - */src/V[!a-zA-Z]* - */src/*/V[!a-zA-Z]* - */src/*/*/V[!a-zA-Z]* - Core/src/Testing - dev - - - - + diff --git a/tests/System/ServiceWhitelist/WhitelistTest.php b/tests/System/ServiceWhitelist/WhitelistTest.php index afeb998fea74..43863de310a2 100644 --- a/tests/System/ServiceWhitelist/WhitelistTest.php +++ b/tests/System/ServiceWhitelist/WhitelistTest.php @@ -21,18 +21,21 @@ use Google\Cloud\Core\Timestamp; use Google\Cloud\PubSub\PubSubClient; use Google\Cloud\Core\Testing\System\SystemTestCase; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; /** * @group whitelist */ class WhitelistTest extends SystemTestCase { + use AssertStringContains; + const MESSAGE = 'NOTE: Error may be due to Whitelist Restriction.'; const TESTING_PREFIX = 'gcloud_whitelist_testing_'; private $keyFilePath; - public function setUp() + public function set_up() { $this->markTestSkipped('Temporarily removed from the system test suite.'); if (!getenv('GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH')) { @@ -151,6 +154,6 @@ private function checkException(callable $call) $this->assertTrue($thrown); $this->assertInstanceOf(NotFoundException::class, $ex); - $this->assertContains(self::MESSAGE, $ex->getMessage()); + $this->assertStringContainsString(self::MESSAGE, $ex->getMessage()); } }