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

Get test suite running #100

Merged
merged 13 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 3 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
php: [8.2]
laravel: [9.*, 10.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
framework: ^9.0
testbench: 7.*
- laravel: 10.*
framework: ^10.0
testbench: 8.*
php: [8.2, 8.3]
laravel: [11.*]
dependency-version: [prefer-stable]
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -40,7 +33,6 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.framework }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
},
"require-dev": {
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^6.0 || ^7.0",
"phpunit/phpunit": "^9.0 || ^10.0",
"orchestra/testbench": "^7.0 || ^8.0",
"nunomaduro/collision": "^6.0 || ^7.0 || ^8.0",
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
"spatie/laravel-ray": "^1.35",
"spatie/test-time": "^1.2"
},
Expand Down
6 changes: 0 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
Expand Down
12 changes: 9 additions & 3 deletions src/Types/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ abstract class Event
{
abstract protected function rule(): RRuleInterface;

public function __construct(protected Entry $event)
{
}
public function __construct(protected Entry $event) {}

public function __get(string $key): mixed
{
return $this->event->$key;
}

/*
Can remove this once https://github.com/statamic/cms/pull/11402 is released
*/
public function __isset(string $key): bool
{
return isset($this->event->$key);
}

public function endTime(): string
{
return $this->end_time ?? now()->endOfDay()->toTimeString();
Expand Down
213 changes: 105 additions & 108 deletions tests/Feature/EventsOffsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,118 +3,115 @@
namespace TransformStudios\Events\Tests\Feature;

use Illuminate\Support\Carbon;
use Statamic\Facades\Cascade;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Entry;
use TransformStudios\Events\Tags\Events;
use TransformStudios\Events\Tests\PreventSavingStacheItemsToDisk;
use TransformStudios\Events\Tests\TestCase;

class EventsOffsetTest extends TestCase
{
use PreventSavingStacheItemsToDisk;

private Events $tag;

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

Entry::make()
->collection('events')
->slug('recurring-event')
->id('recurring-event')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'categories' => ['one'],
])->save();

$this->tag = app(Events::class);
}

/** @test */
public function canOffsetUpcomingOccurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag
->setContext([])
->setParameters([
'collection' => 'events',
'limit' => 5,
'offset' => 2,
]);

$occurrences = $this->tag->upcoming();

$this->assertCount(3, $occurrences);
}

/** @test */
public function canOffsetBetweenOccurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'from' => Carbon::now()->toDateString(),
'to' => Carbon::now()->addWeek(3),
'offset' => 2,
]);

$occurrences = $this->tag->between();

$this->assertCount(2, $occurrences);
}

/** @test */
public function canOffsetTodayOccurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));

Entry::make()
->collection('events')
->slug('single-event')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '13:00',
'end_time' => '15:00',
])->save();

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(1, $this->tag->today());

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'ignore_finished' => true,
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}

/** @test */
public function canOffsetSingleDayOccurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}
private Events $tag;

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

Entry::make()
->collection('events')
->slug('recurring-event')
->id('recurring-event')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'categories' => ['one'],
])->save();

$this->tag = app(Events::class);
}

#[Test]
public function can_offset_upcoming_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag
->setContext([])
->setParameters([
'collection' => 'events',
'limit' => 5,
'offset' => 2,
]);

$occurrences = $this->tag->upcoming();

$this->assertCount(3, $occurrences);
}

#[Test]
public function can_offset_between_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'from' => Carbon::now()->toDateString(),
'to' => Carbon::now()->addWeek(3),
'offset' => 2,
]);

$occurrences = $this->tag->between();

$this->assertCount(2, $occurrences);
}

#[Test]
public function can_offset_today_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));

Entry::make()
->collection('events')
->slug('single-event')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '13:00',
'end_time' => '15:00',
])->save();

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(1, $this->tag->today());

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'ignore_finished' => true,
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}

#[Test]
public function can_offset_single_day_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}
}
32 changes: 15 additions & 17 deletions tests/Feature/IcsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace TransformStudios\Events\Tests\Feature;

use Illuminate\Support\Carbon;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Entry;
use TransformStudios\Events\Tests\PreventSavingStacheItemsToDisk;
use TransformStudios\Events\Tests\TestCase;

class IcsControllerTest extends TestCase
{
use PreventSavingStacheItemsToDisk;

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

Expand All @@ -28,8 +26,8 @@ public function setUp(): void
])->save();
}

/** @test */
public function canCreateSingleDayEventIcsFile()
#[Test]
public function can_create_single_day_event_ics_file()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Expand All @@ -38,12 +36,12 @@ public function canCreateSingleDayEventIcsFile()
'event' => 'the-id',
]))->assertDownload('single-event.ics');

$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent());
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
}

/** @test */
public function canCreateSingleDayRecurringEventIcsFile()
#[Test]
public function can_create_single_day_recurring_event_ics_file()
{
Carbon::setTestNow(now()->addDay()->setTimeFromTimeString('10:00'));

Expand All @@ -64,16 +62,16 @@ public function canCreateSingleDayRecurringEventIcsFile()
'event' => 'the-recurring-id',
]))->assertDownload('recurring-event.ics');

$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent());
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());

$this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'the-recurring-id',
]))->assertStatus(404);
}

/** @test */
public function canCreateSingleDayMultidayEventIcsFile()
#[Test]
public function can_create_single_day_multiday_event_ics_file()
{
Carbon::setTestNow(now());

Expand Down Expand Up @@ -113,11 +111,11 @@ public function canCreateSingleDayMultidayEventIcsFile()
'event' => 'the-multi-day-event',
]))->assertDownload('multi-day-event.ics');

$this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent());
$this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
}

/** @test */
public function throws404ErrorWhenEventDoesNotOccurOnDate()
#[Test]
public function throws404_error_when_event_does_not_occur_on_date()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Expand All @@ -127,8 +125,8 @@ public function throws404ErrorWhenEventDoesNotOccurOnDate()
]))->assertStatus(404);
}

/** @test */
public function throws404ErrorWhenEventDoesNotExist()
#[Test]
public function throws404_error_when_event_does_not_exist()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Expand Down
Loading
Loading