Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Domain\Package\PackageTest.php tests #90

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 111 additions & 60 deletions tests/Unit/Domain/Package/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,118 +41,169 @@ public function testDescription(): void {
$this->assertSame('An awesome package description', $this->package->getDescription());
}

public function testDescriptionHasBeenUpdated(): void {
public function testObjectIsInItsInitialState(): void {
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getCreatedAt());
$this->assertFalse($this->package->isDirty());
$this->assertNull($this->package->getUpdatedAt());
}

/**
* @depends testObjectIsInItsInitialState
*/
public function testDescriptionHasBeenUpdated(): array {
$package = $this->package->withDescription('Even awesomer description');

$this->package = $this->package->withDescription('Even awesomer description');
$this->assertSame('Even awesomer description', $package->getDescription());

$this->assertTrue($this->package->isDirty());
$this->assertSame('Even awesomer description', $this->package->getDescription());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

public function testDescriptionDoesNotUpdateWhenItsTheSame(): void {
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getCreatedAt());
$this->assertFalse($this->package->isDirty());
$this->assertNull($this->package->getUpdatedAt());
/**
* @depends testObjectIsInItsInitialState
*/
public function testDescriptionDoesNotUpdateWhenItsTheSame(): array {
$package = $this->package->withDescription('An awesome package description');

$this->package = $this->package->withDescription('An awesome package description');
$this->assertSame('An awesome package description', $package->getDescription());

$this->assertFalse($this->package->isDirty());
$this->assertSame('An awesome package description', $this->package->getDescription());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertNull($this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

public function testLatestVersion(): void {
$this->assertSame('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());
/**
* @depends testObjectIsInItsInitialState
*/
public function testLatestVersionHasBeenUpdated(): array {
$package = $this->package->withLatestVersion('1.0.1');

$this->package = $this->package->withLatestVersion('1.0.1');
$this->assertSame('1.0.1', $package->getLatestVersion());

$this->assertTrue($this->package->isDirty());
$this->assertSame('1.0.1', $this->package->getLatestVersion());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

public function testLatestVersionDoesNotUpdateWhenItsTheSame(): void {
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getCreatedAt());
$this->assertFalse($this->package->isDirty());
$this->assertNull($this->package->getUpdatedAt());
/**
* @depends testObjectIsInItsInitialState
*/
public function testLatestVersionDoesNotUpdateWhenItsTheSame(): array {
$package = $this->package->withLatestVersion('1.0');

$this->package = $this->package->withLatestVersion('1.0');
$this->assertSame('1.0', $package->getLatestVersion());

$this->assertFalse($this->package->isDirty());
$this->assertSame('1.0', $this->package->getLatestVersion());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertNull($this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

public function testUrl(): void {
$this->assertSame('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());
/**
* @depends testObjectIsInItsInitialState
*/
public function testUrlHasBeenUpdated(): array {
$package = $this->package->withUrl('https://');

$this->package = $this->package->withUrl('https://');
$this->assertSame('https://', $package->getUrl());

$this->assertTrue($this->package->isDirty());
$this->assertSame('https://', $this->package->getUrl());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

public function testUrlDoesNotUpdateWhenItsTheSame(): void {
$this->assertInstanceOf(DateTimeImmutable::class, $this->package->getCreatedAt());
$this->assertFalse($this->package->isDirty());
$this->assertNull($this->package->getUpdatedAt());
/**
* @depends testObjectIsInItsInitialState
*/
public function testUrlDoesNotUpdateWhenItsTheSame(): array {
$package = $this->package->withUrl('http://');

$this->package = $this->package->withUrl('http://');
$this->assertSame('http://', $package->getUrl());

$this->assertFalse($this->package->isDirty());
$this->assertSame('http://', $this->package->getUrl());
$this->assertSame($this->createdAt, $this->package->getCreatedAt());
$this->assertNull($this->package->getUpdatedAt());
return [$package, $this->createdAt];
}

/**
* @depends testDescriptionHasBeenUpdated
* @depends testLatestVersionHasBeenUpdated
* @depends testUrlHasBeenUpdated
*/
public function testIsDirty(array $testData): void {
[$package,] = $testData;

$this->assertTrue($package->isDirty());
}

/**
* @depends testDescriptionHasBeenUpdated
* @depends testLatestVersionHasBeenUpdated
* @depends testUrlHasBeenUpdated
*/
public function testSameCreatedAt(array $testData): void {
[$package, $createdAt] = $testData;

$this->assertSame($createdAt, $package->getCreatedAt());
}

/**
* @depends testDescriptionHasBeenUpdated
* @depends testLatestVersionHasBeenUpdated
* @depends testUrlHasBeenUpdated
*/
public function testUpdatedAt(array $testData): void {
[$package,] = $testData;

$this->assertInstanceOf(DateTimeImmutable::class, $package->getUpdatedAt());
}

/**
* @depends testDescriptionDoesNotUpdateWhenItsTheSame
* @depends testLatestVersionDoesNotUpdateWhenItsTheSame
* @depends testUrlDoesNotUpdateWhenItsTheSame
*/
public function testUpdatedAtIsNull(array $testData): void {
[$package,] = $testData;

$this->assertNull($package->getUpdatedAt());
}

public function testJsonSerializeWhenPackageWasNotUpdated() {
$packageWasNotUpdated = array_merge(
$packageAttributes = array_merge(
$this->packageAttributes,
[
'createdAt' => $this->createdAt,
'updatedAt' => null
]
);

$this->assertIsArray($this->package->jsonSerialize());
$this->assertSame($packageWasNotUpdated, $this->package->jsonSerialize());
$this->assertNull($this->package->getUpdatedAt());

return [$this->package, $packageAttributes];
}

public function testJsonSerializeWhenPackageWasUpdated(): void {
$this->package = $this->package->withLatestVersion('1.0.1');
public function testJsonSerializeWhenPackageWasUpdated(): array {
$package = $this->package->withLatestVersion('1.0.1');

$packageWasUpdated = array_merge(
$packageAttributes = array_merge(
$this->packageAttributes,
[
'latestVersion' => '1.0.1',
'createdAt' => $this->createdAt,
'updatedAt' => $this->package->getUpdatedAt()
'updatedAt' => $package->getUpdatedAt()
]
);

$this->assertIsArray($this->package->jsonSerialize());
$this->assertSame($packageWasUpdated, $this->package->jsonSerialize());
$this->assertInstanceOf(DateTimeImmutable::class, $package->getUpdatedAt());

return [$package, $packageAttributes];
}

/**
* @depends testJsonSerializeWhenPackageWasNotUpdated
* @depends testJsonSerializeWhenPackageWasUpdated
*/
public function testObjectSerializedValuesMatch(array $testData): void {
[$preference, $preferenceAttributes] = $testData;

$this->assertIsArray($preference->jsonSerialize());
$this->assertSame($preferenceAttributes, $preference->jsonSerialize());
}
}