Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
#5 Test coverage improvements for GulpBundleAssets_Bundles classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Silic0nS0ldier committed Apr 6, 2019
1 parent 4686171 commit a2223ee
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/AssetBundles/GulpBundleAssetsRawBundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($path)
}

// Verify bundle key is an object
if (is_object($schema['bundle'])) {
if (!is_array($schema['bundle'])) {
throw new InvalidBundlesFileException("Encountered issue processing bundle property of schema from file '$path'");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function urlPathToAbsolutePath($uncleanRelativePath)
if ($absolutePath) {
return $absolutePath;
} else {
return;
return null;
}
}

Expand Down
31 changes: 25 additions & 6 deletions tests/AssetBundles/GulpBundleAssetsCompiledBundlesTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use UserFrosting\Assets\Assets;
use UserFrosting\Assets\AssetBundles\GulpBundleAssetsCompiledBundles;
use UserFrosting\Assets\Assets;
use UserFrosting\Assets\Exception\InvalidBundlesFileException;

/**
* Tests GulpBundleAssetsCompiledBundles class.
Expand All @@ -15,20 +16,38 @@ class GulpBundleAssetsCompiledBundlesTest extends TestCase
*
* @return Assets
*/
public function testConstructGulpBundleAssetsCompiledBundles()
public function testConstruct()
{
$bundles = new GulpBundleAssetsCompiledBundles(__DIR__ . "/../data/bundle.result.json");
$this->assertInstanceOf(GulpBundleAssetsCompiledBundles::class, $bundles);
return $bundles;
}

/**
* Tests GulpBundleAssetsCompiledBundles constructor when a bundle contains an invalid styles property.
*/
public function testConstructInvalidStylesBundle()
{
$this->expectException(InvalidBundlesFileException::class);
new GulpBundleAssetsCompiledBundles(__DIR__ . "/../data/bundle.result.bad-styles.json");
}

/**
* Tests GulpBundleAssetsCompiledBundles constructor when a bundle contains an invalid scripts property.
*/
public function testConstructInvalidJsBundle()
{
$this->expectException(InvalidBundlesFileException::class);
new GulpBundleAssetsCompiledBundles(__DIR__ . "/../data/bundle.result.bad-scripts.json");
}

/**
* Tests getCssBundleAssets method.
*
* @param GulpBundleAssetsCompiledBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsCompiledBundles
* @depends testConstruct
*/
public function testGetCssBundleAssets(GulpBundleAssetsCompiledBundles $bundles)
{
Expand All @@ -43,7 +62,7 @@ public function testGetCssBundleAssets(GulpBundleAssetsCompiledBundles $bundles)
* @param GulpBundleAssetsCompiledBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsCompiledBundles
* @depends testConstruct
*/
public function testGetCssBundleAssetsOutOfRange(GulpBundleAssetsCompiledBundles $bundles)
{
Expand All @@ -57,7 +76,7 @@ public function testGetCssBundleAssetsOutOfRange(GulpBundleAssetsCompiledBundles
* @param GulpBundleAssetsCompiledBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsCompiledBundles
* @depends testConstruct
*/
public function testGetJsBundleAssets(GulpBundleAssetsCompiledBundles $bundles)
{
Expand All @@ -72,7 +91,7 @@ public function testGetJsBundleAssets(GulpBundleAssetsCompiledBundles $bundles)
* @param GulpBundleAssetsCompiledBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsCompiledBundles
* @depends testConstruct
*/
public function testGetJsBundleAssetsOutOfRange(GulpBundleAssetsCompiledBundles $bundles)
{
Expand Down
59 changes: 48 additions & 11 deletions tests/AssetBundles/GulpBundleAssetsRawBundlesTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use PHPUnit\Framework\TestCase;
use UserFrosting\Assets\Assets;
use UserFrosting\Assets\AssetBundles\GulpBundleAssetsRawBundles;
use UserFrosting\Support\Exception\JsonException;
use UserFrosting\Assets\Assets;
use UserFrosting\Assets\Exception\InvalidBundlesFileException;
use UserFrosting\Support\Exception\FileNotFoundException;
use UserFrosting\Support\Exception\JsonException;

/**
* Tests GulpBundleAssetsRawBundles class.
Expand All @@ -17,29 +18,65 @@ class GulpBundleAssetsRawBundlesTest extends TestCase
*
* @return Assets
*/
public function testConstructGulpBundleAssetsRawBundles()
public function testConstruct()
{
$bundles = new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.json");
$this->assertInstanceOf(GulpBundleAssetsRawBundles::class, $bundles);
return $bundles;
}

/**
* Tests GulpBundleAssetsRawBundles constructor with a config that has no bundles property.
*/
public function testConstructStubConfig()
{
$bundles = new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.stub.json");
$this->assertInstanceOf(GulpBundleAssetsRawBundles::class, $bundles);
}

/**
* Tests GulpBundleAssetsRawBundles constructor with config containing invalid syntax.
*/
public function testConstructGulpBundleAssetsRawBundlesInvalidSyntax()
public function testConstructInvalidSyntax()
{
$this->expectException(JsonException::class);
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.invalid.json");
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.invalid-syntax.json");
}

/**
* Tests GulpBundleAssetsRawBundles constructor with missing config.
*/
public function testConstructGulpBundleAssetsRawBundlesNotFound()
public function testConstructNotFound()
{
$this->expectException(FileNotFoundException::class);
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.nothere.json");
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.not-here.json");
}

/**
* Tests GulpBundleAssetsRawBundles constructor when the bundle property is the incorrect type.
*/
public function testConstructInvalidBundlesPropertyType()
{
$this->expectException(InvalidBundlesFileException::class);
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.bad-bundle.json");
}

/**
* Tests GulpBundleAssetsRawBundles constructor when a bundle contains an invalid styles property.
*/
public function testConstructInvalidStylesBundle()
{
$this->expectException(InvalidBundlesFileException::class);
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.bad-styles.json");
}

/**
* Tests GulpBundleAssetsRawBundles constructor when a bundle contains an invalid scripts property.
*/
public function testConstructInvalidJsBundle()
{
$this->expectException(InvalidBundlesFileException::class);
new GulpBundleAssetsRawBundles(__DIR__ . "/../data/bundle.config.bad-scripts.json");
}

/**
Expand All @@ -48,7 +85,7 @@ public function testConstructGulpBundleAssetsRawBundlesNotFound()
* @param GulpBundleAssetsRawBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsRawBundles
* @depends testConstruct
*/
public function testGetCssBundleAssets(GulpBundleAssetsRawBundles $bundles)
{
Expand All @@ -63,7 +100,7 @@ public function testGetCssBundleAssets(GulpBundleAssetsRawBundles $bundles)
* @param GulpBundleAssetsRawBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsRawBundles
* @depends testConstruct
*/
public function testGetCssBundleAssetsOutOfRange(GulpBundleAssetsRawBundles $bundles)
{
Expand All @@ -77,7 +114,7 @@ public function testGetCssBundleAssetsOutOfRange(GulpBundleAssetsRawBundles $bun
* @param GulpBundleAssetsRawBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsRawBundles
* @depends testConstruct
*/
public function testGetJsBundleAssets(GulpBundleAssetsRawBundles $bundles)
{
Expand All @@ -93,7 +130,7 @@ public function testGetJsBundleAssets(GulpBundleAssetsRawBundles $bundles)
* @param GulpBundleAssetsRawBundles $bundles
* @return void
*
* @depends testConstructGulpBundleAssetsRawBundles
* @depends testConstruct
*/
public function testGetJsBundleAssetsOutOfRange(GulpBundleAssetsRawBundles $bundles)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/data/bundle.config.bad-bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundle": true
}
8 changes: 8 additions & 0 deletions tests/data/bundle.config.bad-scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bundle": {
"test": {
"scripts": false,
"styles": "vendor/bootstrap/css/bootstrap.css"
}
}
}
11 changes: 11 additions & 0 deletions tests/data/bundle.config.bad-styles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"bundle": {
"test": {
"scripts": [
"vendor/bootstrap/js/bootstrap.js",
"vendor/bootstrap/js/npm.js"
],
"styles": 256
}
}
}
1 change: 1 addition & 0 deletions tests/data/bundle.config.stub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
6 changes: 6 additions & 0 deletions tests/data/bundle.result.bad-scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"test": {
"scripts": [ "test-930fa5c1ee.js" ],
"styles": "test-930fa5c1ee.css"
}
}
6 changes: 6 additions & 0 deletions tests/data/bundle.result.bad-styles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"test": {
"scripts": "test-930fa5c1ee.js",
"styles": [ "test-930fa5c1ee.css" ]
}
}

0 comments on commit a2223ee

Please sign in to comment.