Skip to content

Commit

Permalink
➕ ADDS: tests for invalid slug during activation in integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmoodak committed Jul 5, 2023
1 parent d6e7b3e commit 6a6a13f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion integrations/integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function register( $integration ): void {

$slug = $integration->get_slug();

if ( isset( $this->integrations[ $slug ] ) ) {
if ( null !== $this->get( $slug ) ) {
throw new InvalidArgumentException( sprintf( 'Integration with slug "%s" is already registered.', $slug ) );
}

Expand Down
13 changes: 13 additions & 0 deletions tests/vip-integrations/test-vip-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ public function test__non_integration_subclass__throws_invalidArgumentException(

$integrations->register( $random_class );
}

/**
* Test activating integration on invalid slug throws error.
*/
public function test__activating_integration_by_passing_invalid_slug__throws_invalidArgumentException() {
$this->expectException( InvalidArgumentException::class );

$integrations = new Integrations();
$fake_integration = new FakeIntegration( 'fake' );

$integrations->register( $fake_integration );
$integrations->activate( 'invalid-slug' );
}
}

0 comments on commit 6a6a13f

Please sign in to comment.