Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add trait for wiring test assertions

  • Loading branch information...
commit bf8c73ce384ee325623f0554fbcaecfa80860406 1 parent 29c646d
@pmjones pmjones authored
Showing with 89 additions and 0 deletions.
  1. +1 −0  src.php
  2. +88 −0 src/Aura/Framework/Test/WiringAssertionsTrait.php
View
1  src.php
@@ -14,6 +14,7 @@
require_once __DIR__ . '/src/Aura/Framework/Intl/TranslatorFactory.php';
require_once __DIR__ . '/src/Aura/Framework/Signal/Manager.php';
require_once __DIR__ . '/src/Aura/Framework/System.php';
+require_once __DIR__ . '/src/Aura/Framework/Test/WiringAssertionsTrait.php';
require_once __DIR__ . '/src/Aura/Framework/View/Helper/Route.php';
require_once __DIR__ . '/src/Aura/Framework/Web/Controller/AbstractPage.php';
require_once __DIR__ . '/src/Aura/Framework/Web/Controller/Factory.php';
View
88 src/Aura/Framework/Test/WiringAssertionsTrait.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ *
+ * This file is part of the Aura project for PHP.
+ *
+ * @package Aura.Framework
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ */
+namespace Aura\Framework\Test;
+
+/**
+ *
+ * A trait for assertions when testing config wiring. You should use
+ * this trait in a class that extends PHPUnit_Framework_TestCase, and you
+ * should call $this->loadDi() in your setup method.
+ *
+ * @package Aura.Framework
+ *
+ */
+trait WiringAssertionsTrait
+{
+ /**
+ *
+ * The DI container from the framework.
+ *
+ * @var Aura\Di\Container
+ *
+ */
+ protected $di;
+
+ /**
+ *
+ * Loads the $di property from the global variable $AURA_FRAMEWORK_DI.
+ *
+ * @return void
+ *
+ */
+ protected function loadDi()
+ {
+ $this->di = $GLOBALS['AURA_FRAMEWORK_DI'];
+ }
+
+ /**
+ *
+ * Asserts that a DI service is an instance of a particular class. This
+ * tests that the service is instantiated without wiring errors; whether
+ * or not the wiring is sane is something else entirely.
+ *
+ * @param string $service The service name.
+ *
+ * @param string $class The class name.
+ *
+ * @return void
+ *
+ */
+ protected function assertGet($service, $class)
+ {
+ $object = $this->di->get($service);
+ $this->assertInstanceOf($class, $object);
+ return $object;
+ }
+
+ /**
+ *
+ * Asserts that a new instance is of a particular class. This tests that
+ * the class is instantiated without wiring errors; whether or not the
+ * wiring is sane is something else entirely.
+ *
+ * @param string $expect Should be an instance of this class.
+ *
+ * @param string $actual An alternative class to instantiate; useful for
+ * mocks of abstract expected classes.
+ *
+ * @return void
+ *
+ */
+ protected function assertNewInstance($expect, $actual = null)
+ {
+ if (! $actual) {
+ $actual = $expect;
+ }
+ $object = $this->di->newInstance($actual);
+ $this->assertInstanceOf($expect, $object);
+ return $object;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.