3333 */
3434class AuthAppContext implements Context {
3535 private FeatureContext $ featureContext ;
36- private array $ allCreatedTokens = [];
3736
3837 /**
3938 * @BeforeScenario
@@ -50,89 +49,56 @@ public function before(BeforeScenarioScope $scope): void {
5049 }
5150
5251 /**
53- * @When the administrator creates app token with expiration time :expiration using the API
52+ * @When user :user creates app token with expiration time :expiration using the auth-app API
5453 *
54+ * @param string $user
5555 * @param string $expiration
5656 *
5757 * @return void
5858 */
59- public function theAdministratorCreatesAppTokenForUserWithExpirationTimeUsingTheApi ( string $ expiration ): void {
59+ public function userCreatesAppTokenWithExpirationTimeUsingTheAuthAppApi ( string $ user , string $ expiration ): void {
6060 $ this ->featureContext ->setResponse (
6161 AuthAppHelper::createAppAuthToken (
6262 $ this ->featureContext ->getBaseUrl (),
63- $ this ->featureContext ->getAdminUsername ( ),
64- $ this ->featureContext ->getAdminPassword ( ),
63+ $ this ->featureContext ->getActualUsername ( $ user ),
64+ $ this ->featureContext ->getPasswordForUser ( $ user ),
6565 $ expiration ,
6666 )
6767 );
6868 }
6969
7070 /**
71- * @Given the administrator has created app token with expiration time :expiration using the API
71+ * @Given user :user has created app token with expiration time :expiration
7272 *
73+ * @param string $user
7374 * @param string $expiration
7475 *
7576 * @return void
7677 */
77- public function theAdministratorHasCreatedAppTokenWithExpirationTimeUsingTheApi ( string $ expiration ): void {
78+ public function userHasCreatedAppTokenWithExpirationTime ( string $ user , string $ expiration ): void {
7879 $ response = AuthAppHelper::createAppAuthToken (
7980 $ this ->featureContext ->getBaseUrl (),
80- $ this ->featureContext ->getAdminUsername ( ),
81- $ this ->featureContext ->getAdminPassword ( ),
81+ $ this ->featureContext ->getActualUsername ( $ user ),
82+ $ this ->featureContext ->getPasswordForUser ( $ user ),
8283 $ expiration ,
8384 );
8485 $ this ->featureContext ->theHTTPStatusCodeShouldBe (200 , "" , $ response );
8586 }
8687
8788 /**
88- * @When admin lists all created tokens
89+ * @When user :user lists all created tokens using the auth-app API
90+ *
91+ * @param string $user
8992 *
9093 * @return void
9194 */
92- public function adminListsAllCreatedTokens ( ): void {
95+ public function userListsAllCreatedTokensUsingTheAuthAppApi ( string $ user ): void {
9396 $ this ->featureContext ->setResponse (
94- AuthAppHelper::listAllAppAuthToken (
97+ AuthAppHelper::listAllAppAuthTokensForUser (
9598 $ this ->featureContext ->getBaseUrl (),
96- $ this ->featureContext ->getAdminUsername ( ),
97- $ this ->featureContext ->getAdminPassword ( ),
99+ $ this ->featureContext ->getActualUsername ( $ user ),
100+ $ this ->featureContext ->getPasswordForUser ( $ user ),
98101 )
99102 );
100103 }
101-
102- /**
103- * @return void
104- */
105- public function deleteAllToken () : void {
106- $ response = AuthAppHelper::listAllAppAuthToken (
107- $ this ->featureContext ->getBaseUrl (),
108- $ this ->featureContext ->getAdminUsername (),
109- $ this ->featureContext ->getAdminPassword (),
110- );
111- $ this ->featureContext ->theHTTPStatusCodeShouldBe (200 , "" , $ response );
112- $ rawBody = $ response ->getBody ()->getContents ();
113- $ tokens = json_decode ($ rawBody );
114- foreach ($ tokens as $ token ) {
115- $ this ->featureContext ->theHTTPStatusCodeShouldBe (
116- 200 ,
117- "" ,
118- AuthAppHelper::deleteAppAuthToken (
119- $ this ->featureContext ->getBaseUrl (),
120- $ this ->featureContext ->getAdminUsername (),
121- $ this ->featureContext ->getAdminPassword (),
122- $ token ->token
123- )
124- );
125- }
126- }
127-
128- /**
129- * @AfterScenario
130- *
131- * @return void
132- *
133- * @throws Exception|GuzzleException
134- */
135- public function cleanDataAfterTests (): void {
136- $ this ->deleteAllToken ();
137- }
138104}
0 commit comments