VendorTestCase.php 887 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

namespace yiiunit;

use yii\base\NotSupportedException;
use Yii;

/**
 * This is the base class for all yii framework unit tests, which requires
 * external vendor libraries to function.
 */
class VendorTestCase extends TestCase
{
	/**
	 * This method is called before the first test of this test class is run.
	 * Attempts to load vendor autoloader.
	 * @throws \yii\base\NotSupportedException
	 */
	public static function setUpBeforeClass()
	{
21
		$vendorDir = __DIR__ . '/../../vendor';
Qiang Xue committed
22 23 24 25
		if (!is_dir($vendorDir)) {
			// this is used by `yii2-dev`
			$vendorDir = __DIR__ . '/../../../../../vendor';
		}
26 27 28 29 30 31 32 33
		Yii::setAlias('@vendor', $vendorDir);
		$vendorAutoload = $vendorDir . '/autoload.php';
		if (file_exists($vendorAutoload)) {
			require_once($vendorAutoload);
		} else {
			throw new NotSupportedException("Vendor autoload file '{$vendorAutoload}' is missing.");
		}
	}
34
}