Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Milloy committed Feb 10, 2019
1 parent 0c2376e commit 0770b65
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/NowCal/NowCal.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected function getParameter(string $key): string
if ($this->has($key)) {
return $this->getParameterKey($key).':'.$this->getParameterValue($key);
}

if ($this->required($key)) {
throw new \Exception('Key "'.$key.'" is not set but is required');
}
Expand Down
15 changes: 7 additions & 8 deletions src/NowCal/Traits/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ trait HasAttributes
'uid',
'created',
'stamp',
'start',
];

/**
Expand All @@ -50,10 +49,10 @@ trait HasAttributes
protected $required = [
'prodid',
'version',
'start',
'uid',
'created',
'stamp',
'start',
];

/**
Expand All @@ -63,7 +62,7 @@ trait HasAttributes
*
* @var string
*/
protected $start;
public $start;

/**
* This property specifies the date and time that a calendar
Expand All @@ -73,7 +72,7 @@ trait HasAttributes
*
* @var string
*/
protected $end;
public $end;

/**
* This property defines a short summary or subject for the
Expand All @@ -83,7 +82,7 @@ trait HasAttributes
*
* @var string
*/
protected $summary;
public $summary;

/**
* This property defines the intended venue for the activity
Expand All @@ -93,7 +92,7 @@ trait HasAttributes
*
* @var string
*/
protected $location;
public $location;

/**
* Check if the key is allowed to be set.
Expand Down Expand Up @@ -128,7 +127,7 @@ protected function required(string $key): bool
*/
public function start($datetime): self
{
$this->set('start', $this->createDateTime($datetime));
$this->set('start', $datetime);

return $this;
}
Expand All @@ -142,7 +141,7 @@ public function start($datetime): self
*/
public function end($datetime): self
{
$this->set('end', $this->createDateTime($datetime));
$this->set('end', $datetime);

return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/NowCal/Traits/HasStaticAccessors.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait HasStaticAccessors
*
* @return \NowCal\NowCal
*/
public static function build(array $props)
public static function build(array $props = [])
{
return new self($props);
}
Expand All @@ -23,7 +23,7 @@ public static function build(array $props)
*
* @return array
*/
public static function raw(array $props): array
public static function raw(array $props = []): array
{
return self::build($props)->raw;
}
Expand All @@ -35,7 +35,7 @@ public static function raw(array $props): array
*
* @return string
*/
public static function plain(array $props): string
public static function plain(array $props = []): string
{
return self::build($props)->plain;
}
Expand All @@ -47,7 +47,7 @@ public static function plain(array $props): string
*
* @return string
*/
public static function file(array $props): string
public static function file(array $props = []): string
{
return self::build($props)->file;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/NowCal/EndAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\NowCal;

use Carbon\Carbon;
use Tests\TestCase;

class EndAttributeTest extends TestCase
{
/** @test */
public function it_can_get_and_set_a_end_time()
{
$this->nowcal->end($time = 'now');

$this->assertEquals($time, $this->nowcal->end);
}

/** @test */
public function it_casts_end_as_a_datetime()
{
$this->nowcal->end($time = 'October 5, 2019 6:03PM');
$format = 'Ymd\THis\Z';

$this->assertStringContainsString(Carbon::parse($time)->format($format), $this->nowcal->plain);
}
}
24 changes: 24 additions & 0 deletions tests/NowCal/LocationAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\NowCal;

use Tests\TestCase;

class LocationAttributeTest extends TestCase
{
/** @test */
public function it_can_get_and_set_a_end_time()
{
$this->nowcal->location($location = '123 Fake Street NW');

$this->assertEquals($location, $this->nowcal->location);
}

/** @test */
public function it_includes_location_in_its_output()
{
$this->nowcal->location($location = '123 Fake Street NW');

$this->assertStringContainsString($location, $this->nowcal->plain);
}
}
22 changes: 20 additions & 2 deletions tests/NowCal/NowCalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@
class NowCalTest extends TestCase
{
/** @test */
public function it_has_a_test()
public function it_can_get_a_raw_array_output()
{
$this->assertTrue(true);
$raw = $this->nowcal->raw;

$this->assertIsArray($raw);
}

/** @test */
public function it_can_get_a_plaintext_output()
{
$plain = $this->nowcal->plain;

$this->assertIsString($plain);
}

/** @test */
public function it_can_export_a_path_to_a_file()
{
$file = $this->nowcal->file;

$this->assertIsString($file);
}
}
26 changes: 26 additions & 0 deletions tests/NowCal/StartAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\NowCal;

use Carbon\Carbon;
use Tests\TestCase;

class StartAttributeTest extends TestCase
{
/** @test */
public function it_can_get_and_set_a_start_time()
{
$this->nowcal->start($time = 'now');

$this->assertEquals($time, $this->nowcal->start);
}

/** @test */
public function it_casts_start_as_a_datetime()
{
$this->nowcal->start($time = 'October 5, 2019 6:03PM');
$format = 'Ymd\THis\Z';

$this->assertStringContainsString(Carbon::parse($time)->format($format), $this->nowcal->plain);
}
}
24 changes: 24 additions & 0 deletions tests/NowCal/SummaryAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\NowCal;

use Tests\TestCase;

class SummaryAttributeTest extends TestCase
{
/** @test */
public function it_can_get_and_set_a_summary()
{
$this->nowcal->summary($summary = 'lorem ipsum dolor sit');

$this->assertEquals($summary, $this->nowcal->summary);
}

/** @test */
public function it_includes_the_summary_in_its_output()
{
$this->nowcal->summary($summary = 'This is my summary');

$this->assertStringContainsString($summary, $this->nowcal->plain);
}
}
9 changes: 9 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

namespace Tests;

use NowCal\NowCal;
use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected $nowcal;

public function setUp(): void
{
parent::setUp();

$this->nowcal = new NowCal([]);
}
}

0 comments on commit 0770b65

Please sign in to comment.