Skip to content

Conversation

google-labs-jules[bot]
Copy link

This change adds a testing framework (PHPUnit) and a static analysis tool (PHPMD) to the project. It also includes tests for the main API endpoints and refactors the core classes to improve code quality and testability.


PR created automatically by Jules for task 18296974841982686059

- Add PHPUnit for testing and PHPMD for code quality analysis.
- Add tests for the main API endpoints.
- Refactor the core classes to improve code quality and testability.
- Fix naming conventions and remove static access.
- Add `.phpunit.result.cache` to `.gitignore`.
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll acknowledge your comments with a 👀 emoji and then get to work. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

I will automatically address your feedback. For any comments you don't want me to act on, just include (aside).



For security, I will only act on instructions from the user who triggered this task for this pull request.

Comment on lines +20 to +113
class AccessTest extends TestCase
{
public function testConstructor()
{
$pve = $this->getMockBuilder(PVE::class)
->disableOriginalConstructor()
->getMock();

$api = $this->getMockBuilder(ApiPVE::class)
->disableOriginalConstructor()
->getMock();

$pve->expects($this->once())
->method('getApi')
->willReturn($api);

$api->expects($this->once())
->method('get')
->with('access/')
->willReturn(['data' => 'ok']);

$access = new Access($pve, '');
}

public function testDomains()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Domains::class, $access->domains());
}

public function testOpenId()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(OpenId::class, $access->openId());
}

public function testGroups()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Groups::class, $access->groups());
}

public function testRoles()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Roles::class, $access->roles());
}

public function testUsers()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Users::class, $access->users());
}

public function testAcl()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Acl::class, $access->acl());
}

public function testPassword()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Password::class, $access->password());
}

public function testPermission()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Permission::class, $access->permission());
}

public function testTfa()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Tfa::class, $access->tfa());
}

public function testTicket()
{
$pve = $this->createMock(PVE::class);
$access = new Access($pve, '');
$this->assertInstanceOf(Ticket::class, $access->ticket());
}
}

Check warning

Code scanning / PHPMD

Code Size Rules: TooManyPublicMethods Warning test

The class AccessTest has 11 public methods. Consider refactoring AccessTest to keep number of public methods under 10.
Comment on lines +26 to +162
class ClusterTest extends TestCase
{
public function testGet()
{
$pve = $this->getMockBuilder(PVE::class)
->disableOriginalConstructor()
->getMock();

$api = $this->getMockBuilder(ApiPVE::class)
->disableOriginalConstructor()
->getMock();

$pve->expects($this->once())
->method('getApi')
->willReturn($api);

$api->expects($this->once())
->method('get')
->with('cluster/')
->willReturn(['data' => 'ok']);

$cluster = new Cluster($pve, '');
$this->assertEquals(['data' => 'ok'], $cluster->get());
}

public function testAcme()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Acme::class, $cluster->acme());
}

public function testBackup()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Backup::class, $cluster->backup());
}

public function testBackupInfo()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(BackupInfo::class, $cluster->backupInfo());
}

public function testCeph()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Ceph::class, $cluster->ceph());
}

public function testConfig()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Config::class, $cluster->config());
}

public function testFirewall()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Firewall::class, $cluster->firewall());
}

public function testHa()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Ha::class, $cluster->ha());
}

public function testMetrics()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Metrics::class, $cluster->metrics());
}

public function testReplication()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Replication::class, $cluster->replication());
}

public function testSdn()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Sdn::class, $cluster->sdn());
}

public function testLog()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Log::class, $cluster->log());
}

public function testNextId()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(NextId::class, $cluster->nextId());
}

public function testOptions()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Options::class, $cluster->options());
}

public function testResources()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Resources::class, $cluster->resources());
}

public function testStatus()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Status::class, $cluster->status());
}

public function testTasks()
{
$pve = $this->createMock(PVE::class);
$cluster = new Cluster($pve, '');
$this->assertInstanceOf(Tasks::class, $cluster->tasks());
}
}

Check warning

Code scanning / PHPMD

Code Size Rules: TooManyPublicMethods Warning test

The class ClusterTest has 17 public methods. Consider refactoring ClusterTest to keep number of public methods under 10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants