Skip to content

Commit

Permalink
Run tests in Laravel 5.0, 5.1, and 5.2
Browse files Browse the repository at this point in the history
Provide a little more compatibility with Eloquent 5.0, verify unit tests
run and pass when Eloquents 5.0 and 5.1 are loaded, and attempt to test
5.0, 5.1, and 5.2 in Travis.
  • Loading branch information
klaude committed Dec 28, 2015
1 parent a831100 commit 8f1856b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ php:
- "7.0"
- hhvm

env:
- LARAVEL_VERSION="5.0.*"
- LARAVEL_VERSION="5.1.*"
- LARAVEL_VERSION="5.2.*"

before_script:
- composer install --dev
- composer remove --update-with-dependencies illuminate/database illuminate/support
- composer remove --dev --update-with-dependencies illuminate/events
- composer require illuminate/database:${LARAVEL_VERSION} illuminate/support:${LARAVEL_VERSION}
- composer require --dev illuminate/events:${LARAVEL_VERSION}
4 changes: 2 additions & 2 deletions src/HasPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function setPreference($preference, $value)
// Serialize date and JSON-like preference values.
if ($this->isPreferenceDateCastable($preference)) {
$value = $this->fromDateTime($value);
} elseif ($this->isPreferenceJsonCastable($preference) && method_exists($this, 'asJson')) {
$value = $this->asJson($value);
} elseif ($this->isPreferenceJsonCastable($preference)) {
$value = method_exists($this, 'asJson') ? $this->asJson($value) : json_encode($value);
}

/** @var Preference $savedPreference */
Expand Down
24 changes: 19 additions & 5 deletions tests/HasPreferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ public function provideInternalTypesInputsAndOutputs()
{
$date = Carbon::now();

return [
// Eloquent 5.0 and 5.1 compatible casts.
$provide = [
'int cast to int' => ['int-preference', 1234, 'int', 1234],
'string cast to int' => ['int-preference', '1234', 'int', 1234],
'integer' => ['integer-preference', 1234, 'int', 1234],
Expand All @@ -220,9 +221,15 @@ public function provideInternalTypesInputsAndOutputs()
'int true cast to bool' => ['bool-preference', 1, 'bool', true],
'array cast to array' => ['array-preference', [1, 2], 'array', [1, 2]],
'json cast to array' => ['json-preference', [1, 2], 'array', [1, 2]],
'timestamp' => ['timestamp-preference', $date, 'int', $date->timestamp],
'unknown types don\'t get cast' => ['undefined-type-preference', '1234', 'string', '1234'],
];

// Eloquent 5.2 compatible casts.
if (method_exists(new Preference, 'asTimeStamp')) {
$provide['timestamp'] = ['timestamp-preference', $date, 'int', $date->timestamp];
}

return $provide;
}

/**
Expand Down Expand Up @@ -251,12 +258,19 @@ public function provideObjectTypesInputsAndOutputs()
$collection = new Collection(['foo']);
$date = Carbon::now();

return [
// Eloquent 5.0 compatible casts.
$provide = [
'object' => ['object-preference', $object, 'stdClass', $object],
'collection' => ['collection-preference', $collection, Collection::class, $collection],
'date' => ['date-preference', $date, Carbon::class, $date],
'datetime' => ['datetime-preference', $date, Carbon::class, $date],
];

// Eloquent 5.1 compatible casts.
if (method_exists(new Preference, 'asDateTime')) {
$provide['date'] = ['date-preference', $date, Carbon::class, $date];
$provide['datetime'] = ['datetime-preference', $date, Carbon::class, $date];
}

return $provide;
}

/**
Expand Down

0 comments on commit 8f1856b

Please sign in to comment.