Permalink
Browse files

Refactor and test Lumen fix

  • Loading branch information...
mattstauffer committed Feb 10, 2018
1 parent c3677ff commit e65e5ddaa4580139473a565fa3d66e7ba9b83818
Showing with 32 additions and 16 deletions.
  1. +8 −12 src/Facades/MailThief.php
  2. +3 −4 tests/TestCase.php
  3. +21 −0 tests/VersionDetectionTest.php
@@ -10,19 +10,15 @@ class MailThief extends Facade
{
protected static function getFacadeAccessor()
{
$appVersion = self::$app->version();
$versions = [];
// Take the first version from whatever string we are passed.
preg_match("/[0-9]\.[0-9]/", $appVersion, $versions);
$appVersion = $versions[0];
$appVersion = (float) $appVersion;
return $appVersion >= 5.5
return self::normalizeAppVersion(self::$app->version()) >= 5.5
? MailThiefFiveFiveCompatible::class
: MailThiefFiveFourCompatible::class;
}
public static function normalizeAppVersion($version)
{
preg_match("/[0-9]*\.[0-9]*/", $version, $versions);
return (float) reset($versions);
}
}
@@ -4,8 +4,8 @@
use Illuminate\Contracts\View\Factory;
use MailThief\MailThiefFiveFourCompatible;
abstract class TestCase extends PHPUnit_Framework_TestCase {
abstract class TestCase extends PHPUnit_Framework_TestCase
{
protected function getViewFactory()
{
return tap(Mockery::mock(Factory::class), function ($factory) {
@@ -55,5 +55,4 @@ protected function getMailThief()
{
return new MailThiefFiveFourCompatible($this->getViewFactory(), $this->getConfigFactory());
}
}
}
@@ -0,0 +1,21 @@
<?php
use MailThief\Facades\MailThief;
class VersionDetectionTest extends TestCase
{
public function test_gets_laravel_versions()
{
$this->assertEquals(5.5, MailThief::normalizeAppVersion('5.5'));
$this->assertEquals(10.4, MailThief::normalizeAppVersion('10.4.1423'));
$this->assertEquals(6.12, MailThief::normalizeAppVersion('6.12.1'));
}
public function test_gets_lumen_versions()
{
$this->assertEquals(5.6, MailThief::normalizeAppVersion('Lumen (5.6.1) (Laravel Components 5.6.*)'));
$this->assertEquals(5.12, MailThief::normalizeAppVersion('Lumen (5.12.4) (Laravel Components 5.99.*)'));
$this->assertEquals(10.2, MailThief::normalizeAppVersion('Lumen 10.2.123'));
$this->assertEquals(4.20, MailThief::normalizeAppVersion('Version 4.20.1423 of the Esteemd Lumen Framework, Blessed Be It'));
}
}

0 comments on commit e65e5dd

Please sign in to comment.