Skip to content

Commit

Permalink
refactor: enable phpunit code quality set for rector (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 4, 2025
1 parent d5ff9cf commit e8b29f7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
14 changes: 7 additions & 7 deletions tests/CacheHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,44 @@ protected function setUp(): void

public function testClose(): void
{
$this->assertTrue($this->handler->close());
self::assertTrue($this->handler->close());
}

public function testDestroy(): void
{
$this->cache->shouldReceive('delete')->with('session:foo')->andReturn(true);

$this->assertTrue($this->handler->destroy('foo'));
self::assertTrue($this->handler->destroy('foo'));
}

public function testGc(): void
{
$this->assertSame(0, $this->handler->gc(100));
self::assertSame(0, $this->handler->gc(100));
}

public function testOpen(): void
{
$this->assertTrue($this->handler->open('root', 'test'));
self::assertTrue($this->handler->open('root', 'test'));
}

public function testRead(): void
{
$this->cache->shouldReceive('get')->with('session:foo')->andReturn('bar');

$this->assertSame('bar', $this->handler->read('foo'));
self::assertSame('bar', $this->handler->read('foo'));
}

public function testReadExpired(): void
{
$this->cache->shouldReceive('get')->with('session:foo')->andReturn(null);

$this->assertSame('', $this->handler->read('foo'));
self::assertSame('', $this->handler->read('foo'));
}

public function testWrite(): void
{
$this->cache->shouldReceive('set')->with('session:foo', 'bar', 86400)->andReturn(true);

$this->assertTrue($this->handler->write('foo', 'bar'));
self::assertTrue($this->handler->write('foo', 'bar'));
}
}
12 changes: 6 additions & 6 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function testConfig(): void
]
]);

$this->assertSame('SID', $c->getCookie());
$this->assertFalse($c->isSecure());
$this->assertSame(86400, $c->getLifetime());
$this->assertNull($c->getSameSite());
$this->assertEquals(new Autowire(FileHandler::class, [
self::assertSame('SID', $c->getCookie());
self::assertFalse($c->isSecure());
self::assertSame(86400, $c->getLifetime());
self::assertNull($c->getSameSite());
self::assertEquals(new Autowire(FileHandler::class, [
'directory' => sys_get_temp_dir()
]), $c->getHandler());
}
Expand All @@ -44,7 +44,7 @@ public function testConfigAutowired(): void
'handler' => new Autowire(FileHandler::class, ['directory' => sys_get_temp_dir()]),
]);

$this->assertEquals(new Autowire(FileHandler::class, [
self::assertEquals(new Autowire(FileHandler::class, [
'directory' => sys_get_temp_dir()
]), $c->getHandler());
}
Expand Down
12 changes: 6 additions & 6 deletions tests/NullHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function testNullHandler(): void
{
$handler = new NullHandler();

$this->assertTrue($handler->destroy('abc'));
$this->assertSame(1, $handler->gc(1));
$this->assertTrue($handler->open('path', '1'));
$this->assertSame('', $handler->read(''));
$this->assertTrue($handler->write('abc', 'data'));
$this->assertTrue($handler->close());
self::assertTrue($handler->destroy('abc'));
self::assertSame(1, $handler->gc(1));
self::assertTrue($handler->open('path', '1'));
self::assertSame('', $handler->read(''));
self::assertTrue($handler->write('abc', 'data'));
self::assertTrue($handler->close());
}
}
86 changes: 43 additions & 43 deletions tests/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function testValueDestroy(): void
$session = $this->factory->initSession('sig');
$session->getSection()->set('key', 'value');

$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));

$session->destroy();
$session->resume();

$this->assertNull($session->getSection()->get('key'));
self::assertNull($session->getSection()->get('key'));
}


Expand All @@ -63,19 +63,19 @@ public function testValueAbort(): void
$session = $this->factory->initSession('sig');
$session->getSection()->set('key', 'value');

$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
$id = $session->getID();

$session->commit();

$session = $this->factory->initSession('sig', $id);
$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
$session->getSection()->set('key', 'value2');
$this->assertSame('value2', $session->getSection()->get('key'));
self::assertSame('value2', $session->getSection()->get('key'));
$session->abort();

$session = $this->factory->initSession('sig', $id);
$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
$session->destroy();
}

Expand All @@ -84,45 +84,45 @@ public function testValueRestart(): void
$session = $this->factory->initSession('sig');
$session->getSection()->set('key', 'value');

$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
$id = $session->getID();
$session->commit();

$session = $this->factory->initSession('sig', $id);
$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
}

public function testValueNewID(): void
{
$session = $this->factory->initSession('sig');
$session->getSection()->set('key', 'value');

$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
$id = $session->regenerateID()->getID();
$session->commit();

$session = $this->factory->initSession('sig', $id);
$this->assertSame('value', $session->getSection()->get('key'));
self::assertSame('value', $session->getSection()->get('key'));
}

public function testSection(): void
{
$session = $this->factory->initSession('sig');
$section = $session->getSection('default');

$this->assertSame('default', $section->getName());
self::assertSame('default', $section->getName());

$section->set('key', 'value');
foreach ($section as $key => $value) {
$this->assertSame('key', $key);
$this->assertSame('value', $value);
self::assertSame('key', $key);
self::assertSame('value', $value);
}

$this->assertSame('key', $key);
$this->assertSame('value', $value);
self::assertSame('key', $key);
self::assertSame('value', $value);

$this->assertSame('value', $section->pull('key'));
$this->assertNull($section->pull('key'));
self::assertSame('value', $section->pull('key'));
self::assertNull($section->pull('key'));
}

public function testSectionClear(): void
Expand All @@ -132,7 +132,7 @@ public function testSectionClear(): void

$section->set('key', 'value');
$section->clear();
$this->assertNull($section->pull('key'));
self::assertNull($section->pull('key'));
}

public function testSectionArrayAccess(): void
Expand All @@ -141,31 +141,31 @@ public function testSectionArrayAccess(): void
$section = $session->getSection('default');

$section['key'] = 'value';
$this->assertSame('value', $section['key']);
self::assertSame('value', $section['key']);
$section->key = 'new value';
$this->assertSame('new value', $section->key);
$this->assertTrue(isset($section['key']));
$this->assertTrue(isset($section->key));
self::assertSame('new value', $section->key);
self::assertArrayHasKey('key', $section);
self::assertTrue(isset($section->key));

$section->delete('key');
$this->assertFalse(isset($section['key']));
$this->assertFalse(isset($section->key));
self::assertArrayNotHasKey('key', $section);
self::assertFalse(isset($section->key));

$section->key = 'new value';
unset($section->key);
$this->assertFalse(isset($section->key));
self::assertFalse(isset($section->key));


$section->key = 'new value';
unset($section['key']);
$this->assertFalse(isset($section->key));
self::assertFalse(isset($section->key));

$section->new = 'another';

$session->commit();

$this->assertNull($section->get('key'));
$this->assertSame('another', $section->get('new'));
self::assertNull($section->get('key'));
self::assertSame('another', $section->get('new'));
}

public function testResumeAndID(): void
Expand All @@ -174,19 +174,19 @@ public function testResumeAndID(): void
$session->resume();
$id = $session->getID();

$this->assertTrue($session->isStarted());
self::assertTrue($session->isStarted());
$session->commit();

$this->assertFalse($session->isStarted());
$this->assertSame($id, $session->getID());
$this->assertFalse($session->isStarted());
self::assertFalse($session->isStarted());
self::assertSame($id, $session->getID());
self::assertFalse($session->isStarted());

$session->destroy();
$this->assertSame($id, $session->getID());
self::assertSame($id, $session->getID());

$this->assertSame($id, $session->__debugInfo()['id']);
self::assertSame($id, $session->__debugInfo()['id']);
$session->regenerateID();
$this->assertNotSame($id, $session->getID());
self::assertNotSame($id, $session->getID());
}

public function testResumeNewSession(): void
Expand All @@ -195,13 +195,13 @@ public function testResumeNewSession(): void
$session->resume();
$id = $session->getID();

$this->assertTrue($session->isStarted());
self::assertTrue($session->isStarted());
$session->commit();

$session = $this->factory->initSession('sig');
$session->resume();

$this->assertNotSame($id, $session->getID());
self::assertNotSame($id, $session->getID());
}

public function testSignatures(): void
Expand All @@ -213,19 +213,19 @@ public function testSignatures(): void
$id = $session->getID();

$session = $this->factory->initSession('sig', $id);
$this->assertSame('value', $session->getSection()->get('key'));
$this->assertSame($id, $session->getID());
self::assertSame('value', $session->getSection()->get('key'));
self::assertSame($id, $session->getID());
$session->commit();

$session = $this->factory->initSession('different', $id);
$this->assertNull($session->getSection()->get('key'));
$this->assertNotSame($id, $session->getID());
self::assertNull($session->getSection()->get('key'));
self::assertNotSame($id, $session->getID());
$session->commit();

// must be dead
$session = $this->factory->initSession('sig', $id);
$this->assertNull($session->getSection()->get('key'));
$this->assertNotSame($id, $session->getID());
self::assertNull($session->getSection()->get('key'));
self::assertNotSame($id, $session->getID());
$session->commit();
}
}

0 comments on commit e8b29f7

Please sign in to comment.