Skip to content

Commit

Permalink
[TASK] Allow Manager::destroy() even if not being initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
ohader committed Aug 30, 2018
1 parent ce3af19 commit a93126f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public static function instance(): self
);
}

public static function destroy()
/**
* @return bool
*/
public static function destroy(): bool
{
if (self::$instance !== null) {
self::$instance = null;
return;
if (self::$instance === null) {
return false;
}
throw new \LogicException(
'Manager was never initialized',
1535189873
);
self::$instance = null;
return true;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ public function instanceResolvesIfCalledTwice()
static::assertSame($firstInstance, $secondInstance);
}

/**
* @test
*/
public function destroyReturnsTrueIfInitialized()
{
Manager::initialize($this->behaviorProphecy->reveal());
static::assertTrue(Manager::destroy());
}

/**
* @test
*/
public function destroyReturnsFalseIfNotInitialized()
{
static::assertFalse(Manager::destroy());
}

/**
* @test
*/
Expand Down

0 comments on commit a93126f

Please sign in to comment.