diff options
author | Joas Schilling <coding@schilljs.com> | 2023-04-04 10:54:12 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-04-04 10:54:12 +0200 |
commit | 131f481a67766d9bc5629948cc0abe1424308f00 (patch) | |
tree | 2967b50bff1b82239749b9689134759ec6b9676c /tests/lib | |
parent | 7fdb23928f793c8eda6b175a602750c718711cfd (diff) | |
download | nextcloud-server-131f481a67766d9bc5629948cc0abe1424308f00.tar.gz nextcloud-server-131f481a67766d9bc5629948cc0abe1424308f00.zip |
fix(initial-state): Log an error when initial-state can not be JSON encoded
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/InitialStateServiceTest.php | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/tests/lib/InitialStateServiceTest.php b/tests/lib/InitialStateServiceTest.php index f4decb43e1e..554478e123f 100644 --- a/tests/lib/InitialStateServiceTest.php +++ b/tests/lib/InitialStateServiceTest.php @@ -27,6 +27,7 @@ namespace Test; use OC\AppFramework\Bootstrap\Coordinator; use OCP\IServerContainer; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use function json_encode; use JsonSerializable; @@ -36,18 +37,22 @@ use stdClass; class InitialStateServiceTest extends TestCase { /** @var InitialStateService */ private $service; + /** @var MockObject|LoggerInterface|(LoggerInterface&MockObject) */ + protected $logger; protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); + $this->service = new InitialStateService( - $this->createMock(LoggerInterface::class), + $this->logger, $this->createMock(Coordinator::class), $this->createMock(IServerContainer::class) ); } - public function staticData() { + public function staticData(): array { return [ ['string'], [23], @@ -63,7 +68,7 @@ class InitialStateServiceTest extends TestCase { /** * @dataProvider staticData */ - public function testStaticData($value) { + public function testStaticData(mixed $value): void { $this->service->provideInitialState('test', 'key', $value); $data = $this->service->getInitialStates(); @@ -73,7 +78,23 @@ class InitialStateServiceTest extends TestCase { ); } - public function testStaticButInvalidData() { + public function testValidDataButFailsToJSONEncode(): void { + $this->logger->expects($this->once()) + ->method('error'); + + $this->service->provideInitialState('test', 'key', ['upload' => INF]); + $data = $this->service->getInitialStates(); + + $this->assertEquals( + [], + $data + ); + } + + public function testStaticButInvalidData(): void { + $this->logger->expects($this->once()) + ->method('warning'); + $this->service->provideInitialState('test', 'key', new stdClass()); $data = $this->service->getInitialStates(); @@ -86,7 +107,7 @@ class InitialStateServiceTest extends TestCase { /** * @dataProvider staticData */ - public function testLazyData($value) { + public function testLazyData(mixed $value): void { $this->service->provideLazyInitialState('test', 'key', function () use ($value) { return $value; }); |