Skip to content

Commit

Permalink
PHPUnit updates
Browse files Browse the repository at this point in the history
  • Loading branch information
troydavisson committed Aug 19, 2016
1 parent 1d6f85b commit e7e8b0f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -24,7 +24,7 @@
"league/csv": ">=6.0"
},
"require-dev": {
"phpunit/phpunit": "4.1.*",
"phpunit/phpunit": "5.*",
"psr/log": "1.*",
"monolog/monolog": "1.10.*",
"gsaulmon/guzzlerecorder": "2.*"
Expand Down
6 changes: 4 additions & 2 deletions tests/CapabilitiesTest.php
Expand Up @@ -14,10 +14,12 @@ public function it_tracks()
$this->assertNull($cpb->get('test'));
}

/** @test **/
/**
* @test
* @expectedException InvalidArgumentException
* **/
public function it_barfs_when_not_given_enough_information_to_build_absolute_urls()
{
$this->setExpectedException('InvalidArgumentException');
$cpb = new Capabilities;
$cpb->add('Login', '/rets/Login');
}
Expand Down
17 changes: 9 additions & 8 deletions tests/ConfigurationTest.php
Expand Up @@ -31,11 +31,13 @@ public function it_loads_config_from_array()
$this->assertSame('pass', $config->getPassword());
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\InvalidConfiguration
**/
public function it_complains_about_bad_config()
{
$this->setExpectedException('PHRETS\\Exceptions\\InvalidConfiguration', "Login URL and Username must be provided");
$config = Configuration::load();
Configuration::load();
}

/** @test **/
Expand Down Expand Up @@ -120,14 +122,13 @@ public function it_keeps_digest_as_the_default()
$this->assertSame(Configuration::AUTH_DIGEST, $c->getHttpAuthenticationMethod());
}

/** @test **/
/**
* @test
* @expectedException InvalidArgumentException
**/
public function it_doesnt_allow_bogus_auth_methods()
{
$c = new Configuration;
$this->setExpectedException(
'\\InvalidArgumentException',
"Given authentication method is invalid. Must be 'basic' or 'digest'"
);
$c->setHttpAuthenticationMethod('bogus');
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Integration/GetMetadataIntegrationTest.php
Expand Up @@ -85,10 +85,12 @@ public function it_gets_keyed_resource_data()
$this->assertInstanceOf('\PHRETS\Models\Metadata\Resource', $resources['Property']);
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\MetadataNotFound
* **/
public function it_errors_with_bad_resource_name()
{
$this->setExpectedException('PHRETS\\Exceptions\\MetadataNotFound');
$this->session->GetResourcesMetadata('Bogus');
}

Expand Down
9 changes: 5 additions & 4 deletions tests/Integration/SearchIntegrationTest.php
Expand Up @@ -119,15 +119,16 @@ public function it_doesnt_die_when_no_count_is_given()
$this->assertCount(40, $results);
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\AutomaticPaginationError
* **/
public function it_detects_broken_pagination()
{
$this->session->Login();

$this->setExpectedException('\PHRETS\Exceptions\AutomaticPaginationError');

// this is manually faked in the fixture
$results = $this->session->Search(
$this->session->Search(
'Property',
'BROKENPAGINATION',
'(LIST_22=90000000+)',
Expand Down
15 changes: 9 additions & 6 deletions tests/Integration/SessionIntegrationTest.php
Expand Up @@ -14,15 +14,17 @@ public function it_logs_in()
/** @test **/
public function it_made_the_request()
{
$connect = $this->session->Login();
$this->session->Login();
$this->assertSame('http://retsgw.flexmls.com:80/rets2_1/Login', $this->session->getLastRequestURL());
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\RETSException
* **/
public function it_throws_an_exception_when_making_a_bad_request()
{
$this->session->Login();
$this->setExpectedException('\PHRETS\Exceptions\RETSException', null, 20203);

$this->session->Search('Property', 'Z', '*'); // no such class by that name
}
Expand Down Expand Up @@ -126,7 +128,10 @@ public function it_detects_when_to_use_user_agent_authentication()
$this->assertArrayHasKey('Accept', $last_request['request']->getHeaders());
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\CapabilityUnavailable
**/
public function it_doesnt_allow_requests_to_unsupported_capabilities()
{
$config = new \PHRETS\Configuration;
Expand All @@ -140,8 +145,6 @@ public function it_doesnt_allow_requests_to_unsupported_capabilities()
$session = new \PHRETS\Session($config);
$session->Login();

$this->setExpectedException('\PHRETS\Exceptions\CapabilityUnavailable');

// make a request for metadata to a server that doesn't support metadata
$session->GetSystemMetadata();
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Models/Metadata/ResourceTest.php
Expand Up @@ -13,10 +13,12 @@ public function it_holds()
$this->assertSame('Test Description', $metadata->getDescription());
}

/** @test **/
/**
* @test
* @expectedException BadMethodCallException
**/
public function it_doesnt_like_bad_methods()
{
$this->setExpectedException('\\BadMethodCallException');
$metadata = new Resource;
$metadata->totallyBogus();
}
Expand Down
14 changes: 6 additions & 8 deletions tests/SessionTest.php
@@ -1,7 +1,6 @@
<?php

use PHRETS\Configuration;
use PHRETS\Http\Client;
use PHRETS\Session;

class SessionTest extends PHPUnit_Framework_TestCase {
Expand All @@ -16,13 +15,12 @@ public function it_builds()
$this->assertSame($c, $s->getConfiguration());
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\MissingConfiguration
*/
public function it_detects_invalid_configurations()
{
$this->setExpectedException(
'PHRETS\\Exceptions\\MissingConfiguration',
"Cannot issue Login without a valid configuration loaded"
);
$c = new Configuration;
$c->setLoginUrl('http://www.reso.org/login');

Expand Down Expand Up @@ -69,7 +67,7 @@ public function it_disables_redirects_when_desired()
/** @test **/
public function it_uses_the_set_logger()
{
$logger = $this->getMock('Logger', ['debug']);
$logger = $this->createMock(\Monolog\Logger::class);

// expect that the string 'Context' will be changed into an array
$logger->expects($this->atLeastOnce())->method('debug')->withConsecutive(
Expand All @@ -89,7 +87,7 @@ public function it_uses_the_set_logger()
/** @test **/
public function it_fixes_the_logger_context_automatically()
{
$logger = $this->getMock('Logger', ['debug']);
$logger = $this->createMock(\Monolog\Logger::class);
// just expect that a debug message is spit out
$logger->expects($this->atLeastOnce())->method('debug')->with($this->matchesRegularExpression('/logger/'));

Expand Down
6 changes: 4 additions & 2 deletions tests/Versions/RETSVersionTest.php
Expand Up @@ -85,10 +85,12 @@ public function it_compares()
$this->assertTrue($v->isAtLeast('1.7.2'));
}

/** @test **/
/**
* @test
* @expectedException \PHRETS\Exceptions\InvalidRETSVersion
* **/
public function it_fails_bad_versions()
{
$this->setExpectedException('PHRETS\\Exceptions\\InvalidRETSVersion', "RETS version '2.0' given is not understood");
$v = new RETSVersion;
$v->setVersion('2.0');
}
Expand Down

0 comments on commit e7e8b0f

Please sign in to comment.