<?php
/**
 * This file is part of the Imbo package
 *
 * (c) Christer Edvartsen <cogo@starzinger.net>
 *
 * For the full copyright and license information, please view the LICENSE file that was
 * distributed with this source code.
 */

namespace ImboUnitTest\Storage;

use Imbo\Exception\ConfigurationException,
    Imbo\Storage\B2;

/**
 * @covers Imbo\Storage\B2
 * @group unit
 * @group storage
 */
class B2Test extends \PHPUnit_Framework_TestCase {
    /**
     * Test that we don't get an exception with required parameters present
     */
    public function testConstructorWithAllRequiredParameters() {
        $b2 = new B2([
            'accountId' => 'foo',
            'applicationKey' => 'bar',
            'bucketId' => 'spam',
            'bucket' => 'eggs'
        ]);

        $this->assertNotNull($b2);
    }

    /**
     * Test that we _do_ get an exception with required parameters present
     *
     * @expectedException Imbo\Exception\ConfigurationException
     */
    public function testConstructorMissingRequiredParameters() {
        $b2 = new B2([
            'accountId' => '',
            'applicationKey' => 'bar',
            'bucketId' => '',
            'bucket' => 'eggs'
        ]);
    }

    /**
     * Test that we _do_ get exceptions for each single missing parameter
     */
    public function testConstructorEachMissingRequiredParameters() {
        $params = [
            'accountId' => 'foo',
            'applicationKey' => 'bar',
            'bucketId' => 'spam',
            'bucket' => 'eggs'
        ];

        foreach ($params as $param => $dummy) {
            $local = $params;
            unset($local[$param]);
            $exception = false;

            try {
                new B2($local);
            } catch (ConfigurationException $e) {
                $exception = true;
            } finally {
                $this->assertTrue($exception);
            }
        }
    }


}
Test for B2 constructor exceptions
Test for B2 constructor exceptions
