-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to Domain\Package\Package.php
- Loading branch information
1 parent
45895c3
commit 32f66ef
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php namespace PackageHealth\PHP\Test\Unit\Domain\Package; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
use PackageHealth\PHP\Domain\Package\Package; | ||
|
||
final class PackageTest extends TestCase | ||
{ | ||
private Package $package; | ||
private \DateTimeImmutable $createdAt; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->package = new Package( | ||
name: 'vendor/project', | ||
description: 'An awesome package description', | ||
latestVersion: '1.0', | ||
url: 'http://' | ||
); | ||
|
||
$this->createdAt = $this->package->getCreatedAt(); | ||
} | ||
|
||
public function testName(): void | ||
{ | ||
$this->assertEquals('vendor/project', $this->package->getName()); | ||
} | ||
|
||
public function testVendor(): void | ||
{ | ||
$this->assertEquals('vendor', $this->package->getVendor()); | ||
} | ||
|
||
public function testProject(): void | ||
{ | ||
$this->assertEquals('project', $this->package->getProject()); | ||
} | ||
|
||
public function testDescription(): void | ||
{ | ||
$this->assertEquals('An awesome package description', $this->package->getDescription()); | ||
} | ||
|
||
public function testDescriptionHasBeenUpdated(): void | ||
{ | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getCreatedAt()); | ||
$this->assertFalse($this->package->isDirty()); | ||
$this->assertNull($this->package->getUpdatedAt()); | ||
|
||
$this->package = $this->package->withDescription('Even awesomer description'); | ||
|
||
$this->assertTrue($this->package->isDirty()); | ||
$this->assertEquals('Even awesomer description', $this->package->getDescription()); | ||
$this->assertEquals($this->createdAt, $this->package->getCreatedAt()); | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getUpdatedAt()); | ||
} | ||
|
||
public function testLatestVersion(): void | ||
{ | ||
$this->assertEquals('1.0', $this->package->getLatestVersion()); | ||
} | ||
|
||
public function testLatestversionHasBeenUpdated(): void | ||
{ | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getCreatedAt()); | ||
$this->assertFalse($this->package->isDirty()); | ||
$this->assertNull($this->package->getUpdatedAt()); | ||
|
||
$this->package = $this->package->withLatestVersion('1.0.1'); | ||
|
||
$this->assertTrue($this->package->isDirty()); | ||
$this->assertEquals('1.0.1', $this->package->getLatestVersion()); | ||
$this->assertEquals($this->createdAt, $this->package->getCreatedAt()); | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getUpdatedAt()); | ||
} | ||
|
||
public function testUrl(): void | ||
{ | ||
$this->assertEquals('http://', $this->package->getUrl()); | ||
} | ||
|
||
public function testUrlHasBeenUpdated(): void | ||
{ | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getCreatedAt()); | ||
$this->assertFalse($this->package->isDirty()); | ||
$this->assertNull($this->package->getUpdatedAt()); | ||
|
||
$this->package = $this->package->withUrl('https://'); | ||
|
||
$this->assertTrue($this->package->isDirty()); | ||
$this->assertEquals('https://', $this->package->getUrl()); | ||
$this->assertEquals($this->createdAt, $this->package->getCreatedAt()); | ||
$this->assertInstanceOf(\DateTimeImmutable::class, $this->package->getUpdatedAt()); | ||
} | ||
} |