From 9be62f8209645d3b1899ff22a234fc436e9856d8 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 21 Mar 2016 14:16:44 +0200 Subject: [PATCH] add tests. --- Tests/Action/Api/CreatePlanActionTest.php | 104 ++++++++++++++++++++++ Tests/Request/Api/CreateChargeTest.php | 7 +- Tests/Request/Api/CreateCustomerTest.php | 26 ++++++ Tests/Request/Api/CreatePlanTest.php | 26 ++++++ Tests/Request/Api/ObtainTokenTest.php | 7 +- 5 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 Tests/Action/Api/CreatePlanActionTest.php create mode 100644 Tests/Request/Api/CreateCustomerTest.php create mode 100644 Tests/Request/Api/CreatePlanTest.php diff --git a/Tests/Action/Api/CreatePlanActionTest.php b/Tests/Action/Api/CreatePlanActionTest.php new file mode 100644 index 0000000..c0f7498 --- /dev/null +++ b/Tests/Action/Api/CreatePlanActionTest.php @@ -0,0 +1,104 @@ +assertTrue($rc->isSubclassOf(ActionInterface::class)); + } + + /** + * @test + */ + public function shouldImplementsApiAwareInterface() + { + $rc = new \ReflectionClass(CreatePlanAction::class); + + $this->assertTrue($rc->isSubclassOf(ApiAwareInterface::class)); + } + + /** + * @test + */ + public function couldBeConstructedWithoutAnyArguments() + { + new CreatePlanAction(); + } + + /** + * @test + */ + public function shouldAllowSetKeysAsApi() + { + $action = new CreatePlanAction(); + + $action->setApi(new Keys('publishableKey', 'secretKey')); + } + + /** + * @test + * + * @expectedException \Payum\Core\Exception\UnsupportedApiException + */ + public function throwNotSupportedApiIfNotKeysGivenAsApi() + { + $action = new CreatePlanAction(); + + $action->setApi('not keys instance'); + } + + /** + * @test + */ + public function shouldSupportCreatePlanRequestWithArrayAccessModel() + { + $action = new CreatePlanAction(); + + $this->assertTrue($action->supports(new CreatePlan([]))); + } + + /** + * @test + */ + public function shouldNotSupportCreatePlanRequestWithNotArrayAccessModel() + { + $action = new CreatePlanAction(); + + $this->assertFalse($action->supports(new CreatePlan(new \stdClass()))); + } + + /** + * @test + */ + public function shouldNotSupportNotCreatePlanRequest() + { + $action = new CreatePlanAction(); + + $this->assertFalse($action->supports(new \stdClass())); + } + + /** + * @test + * + * @expectedException \Payum\Core\Exception\RequestNotSupportedException + * @expectedExceptionMessage Action CreatePlanAction is not supported the request stdClass. + */ + public function throwRequestNotSupportedIfNotSupportedGiven() + { + $action = new CreatePlanAction(); + + $action->execute(new \stdClass()); + } +} diff --git a/Tests/Request/Api/CreateChargeTest.php b/Tests/Request/Api/CreateChargeTest.php index 97e2689..dce0bdb 100644 --- a/Tests/Request/Api/CreateChargeTest.php +++ b/Tests/Request/Api/CreateChargeTest.php @@ -1,6 +1,7 @@ assertTrue($rc->isSubclassOf('Payum\Core\Request\Generic')); + $this->assertTrue($rc->isSubclassOf(Generic::class)); } /** @@ -20,6 +21,6 @@ public function shouldBeSubClassOfGeneric() */ public function couldBeConstructedWithModelAsFirstArgument() { - new CreateCharge($model = array()); + new CreateCharge($model = []); } } diff --git a/Tests/Request/Api/CreateCustomerTest.php b/Tests/Request/Api/CreateCustomerTest.php new file mode 100644 index 0000000..da30c1a --- /dev/null +++ b/Tests/Request/Api/CreateCustomerTest.php @@ -0,0 +1,26 @@ +assertTrue($rc->isSubclassOf(Generic::class)); + } + + /** + * @test + */ + public function couldBeConstructedWithModelAsFirstArgument() + { + new CreateCustomer($model = []); + } +} diff --git a/Tests/Request/Api/CreatePlanTest.php b/Tests/Request/Api/CreatePlanTest.php new file mode 100644 index 0000000..92b944b --- /dev/null +++ b/Tests/Request/Api/CreatePlanTest.php @@ -0,0 +1,26 @@ +assertTrue($rc->isSubclassOf(Generic::class)); + } + + /** + * @test + */ + public function couldBeConstructedWithModelAsFirstArgument() + { + new CreatePlan($model = []); + } +} diff --git a/Tests/Request/Api/ObtainTokenTest.php b/Tests/Request/Api/ObtainTokenTest.php index 29af363..bac87dd 100644 --- a/Tests/Request/Api/ObtainTokenTest.php +++ b/Tests/Request/Api/ObtainTokenTest.php @@ -1,6 +1,7 @@ assertTrue($rc->isSubclassOf('Payum\Core\Request\Generic')); + $this->assertTrue($rc->isSubclassOf(Generic::class)); } /** @@ -20,6 +21,6 @@ public function shouldBeSubClassOfGeneric() */ public function couldBeConstructedWithModelAsFirstArgument() { - new ObtainToken($model = array()); + new ObtainToken($model = []); } }