Skip to content

Commit e1a507e

Browse files
committed
Merge pull request parse-community#148 from juliangut/master
Tests PSR4 autoloading
2 parents 6e20e21 + 468fca9 commit e1a507e

27 files changed

+617
-409
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ App just for testing, and deploy some cloud code to it.
2222
* Run "parse deploy" in your cloud folder.
2323
* Paste your App ID, REST API Key, and Master Key in tests/ParseTestHelper.php
2424

25-
You should now be able to execute, from the tests/ folder:
25+
You should now be able to execute, from project root folder:
2626

27-
../vendor/bin/phpunit --stderr .
27+
./vendor/bin/phpunit --stderr .
2828

2929
At present the full suite of tests takes around 20 minutes.
3030

31-
3231
[Get Composer]: https://getcomposer.org/download/
3332
[Contributor License Agreement]: https://developers.facebook.com/opensource/cla
3433
[Create Parse App]: https://parse.com/apps/new

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"Parse\\": "src/Parse/"
2727
}
2828
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Parse\\Test\\": "tests/Parse/"
32+
}
33+
},
2934
"extra": {
3035
"branch-alias": {
3136
"dev-master": "1.1-dev"

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
bootstrap="./tests/bootstrap.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnError="false"
12+
stopOnFailure="false"
13+
stopOnSkipped="false"
14+
stopOnIncomplete="false"
15+
syntaxCheck="false"
16+
verbose="true"
17+
>
18+
<testsuites>
19+
<testsuite>
20+
<directory suffix="Test.php">./tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

tests/Parse/ConfigMock.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Parse\Test;
4+
5+
use Parse\ParseConfig;
6+
7+
class ConfigMock extends ParseConfig
8+
{
9+
public function __construct()
10+
{
11+
$this->setConfig(["foo" => "bar", "some" => 1]);
12+
}
13+
}

tests/ParseTestHelper.php renamed to tests/Parse/Helper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseClient;
46
use Parse\ParseObject;
57
use Parse\ParseQuery;
68

7-
class ParseTestHelper
9+
class Helper
810
{
911
public static function setUp()
1012
{
1113
ini_set('error_reporting', E_ALL);
1214
ini_set('display_errors', 1);
1315
date_default_timezone_set('UTC');
16+
1417
ParseClient::initialize(
1518
'app-id-here',
1619
'rest-api-key-here',
@@ -28,7 +31,8 @@ public static function clearClass($class)
2831
$query->each(
2932
function (ParseObject $obj) {
3033
$obj->destroy(true);
31-
}, true
34+
},
35+
true
3236
);
3337
}
3438
}

tests/IncrementTest.php renamed to tests/Parse/IncrementTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseException;
46
use Parse\ParseObject;
57
use Parse\ParseQuery;
68

7-
require_once 'ParseTestHelper.php';
8-
9-
class IncrementTest extends PHPUnit_Framework_TestCase
9+
class IncrementTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public static function setUpBeforeClass()
1212
{
13-
ParseTestHelper::setUp();
13+
Helper::setUp();
1414
}
1515

1616
public function tearDown()
1717
{
18-
ParseTestHelper::clearClass("TestObject");
19-
ParseTestHelper::tearDown();
18+
Helper::clearClass("TestObject");
19+
Helper::tearDown();
2020
}
2121

2222
public function testIncrementOnFreshObject()
@@ -146,7 +146,8 @@ public function testIncrementNonNumber()
146146
$obj->set('foo', 'bar');
147147
$obj->save();
148148
$this->setExpectedException(
149-
'Parse\ParseException', 'Cannot increment a non-number type'
149+
'Parse\ParseException',
150+
'Cannot increment a non-number type'
150151
);
151152
$obj->increment('foo');
152153
$obj->save();
@@ -163,7 +164,9 @@ public function testIncrementOnDeletedField()
163164
$query->equalTo('objectId', $obj->getObjectId());
164165
$result = $query->first();
165166
$this->assertEquals(
166-
$result->get('yo'), 1, 'Error in increment on deleted field'
167+
$result->get('yo'),
168+
1,
169+
'Error in increment on deleted field'
167170
);
168171
}
169172

@@ -176,7 +179,8 @@ public function testIncrementEmptyFieldOnFreshObject()
176179
$query->equalTo('objectId', $obj->getObjectId());
177180
$result = $query->first();
178181
$this->assertEquals(
179-
$result->get('yo'), 1,
182+
$result->get('yo'),
183+
1,
180184
'Error in increment on empty field of fresh object'
181185
);
182186
}
@@ -196,7 +200,8 @@ public function testIncrementEmptyField()
196200
$queryAgain->equalTo('objectId', $objAgain->getObjectId());
197201
$objectAgainTwo = $queryAgain->first();
198202
$this->assertEquals(
199-
$objectAgainTwo->get('yo'), 2,
203+
$objectAgainTwo->get('yo'),
204+
2,
200205
'Error in increment on empty field'
201206
);
202207
}

tests/ParseACLTest.php renamed to tests/Parse/ParseACLTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseACL;
46
use Parse\ParseObject;
57
use Parse\ParseQuery;
68
use Parse\ParseUser;
79

8-
require_once 'ParseTestHelper.php';
9-
1010
class ParseACLTest extends \PHPUnit_Framework_TestCase
1111
{
1212
public static function setUpBeforeClass()
1313
{
14-
ParseTestHelper::setUp();
14+
Helper::setUp();
1515
}
1616

1717
public function setUp()
1818
{
19-
ParseTestHelper::clearClass("_User");
20-
ParseTestHelper::clearClass("Object");
19+
Helper::clearClass("_User");
20+
Helper::clearClass("Object");
2121
}
2222

2323
public function tearDown()
2424
{
25-
ParseTestHelper::tearDown();
25+
Helper::tearDown();
2626
}
2727

2828
public function testACLAnObjectOwnedByOneUser()
@@ -334,8 +334,8 @@ public function testACLRequiresObjectId()
334334

335335
public function testIncludedObjectsGetACLs()
336336
{
337-
ParseTestHelper::clearClass("Test");
338-
ParseTestHelper::clearClass("Related");
337+
Helper::clearClass("Test");
338+
Helper::clearClass("Related");
339339
$object = ParseObject::create('Test');
340340
$acl = new ParseACL();
341341
$acl->setPublicReadAccess(true);
@@ -357,8 +357,8 @@ public function testIncludedObjectsGetACLs()
357357

358358
public function testIncludedObjectsGetACLWithDefaultACL()
359359
{
360-
ParseTestHelper::clearClass("Test");
361-
ParseTestHelper::clearClass("Related");
360+
Helper::clearClass("Test");
361+
Helper::clearClass("Related");
362362
$defaultACL = new ParseACL();
363363
$defaultACL->setPublicReadAccess(true);
364364
$defaultACL->setPublicWriteAccess(true);

tests/ParseAnalyticsTest.php renamed to tests/Parse/ParseAnalyticsTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

3-
use Parse\ParseAnalytics;
3+
namespace Parse\Test;
44

5-
require_once 'ParseTestHelper.php';
5+
use Parse\ParseAnalytics;
66

7-
class ParseAnalyticsTest extends PHPUnit_Framework_TestCase
7+
class ParseAnalyticsTest extends \PHPUnit_Framework_TestCase
88
{
99
public static function setUpBeforeClass()
1010
{
11-
ParseTestHelper::setUp();
11+
Helper::setUp();
1212
}
1313

1414
public function tearDown()
1515
{
16-
ParseTestHelper::tearDown();
16+
Helper::tearDown();
1717
}
1818

1919
public function assertAnalyticsValidation($event, $params, $expectedJSON)
@@ -34,23 +34,26 @@ public function testTrackEvent()
3434
public function testFailsOnEventName1()
3535
{
3636
$this->setExpectedException(
37-
'Exception', 'A name for the custom event must be provided.'
37+
'Exception',
38+
'A name for the custom event must be provided.'
3839
);
3940
ParseAnalytics::track('');
4041
}
4142

4243
public function testFailsOnEventName2()
4344
{
4445
$this->setExpectedException(
45-
'Exception', 'A name for the custom event must be provided.'
46+
'Exception',
47+
'A name for the custom event must be provided.'
4648
);
4749
ParseAnalytics::track(' ');
4850
}
4951

5052
public function testFailsOnEventName3()
5153
{
5254
$this->setExpectedException(
53-
'Exception', 'A name for the custom event must be provided.'
55+
'Exception',
56+
'A name for the custom event must be provided.'
5457
);
5558
ParseAnalytics::track(" \n");
5659
}

tests/ParseBytesTest.php renamed to tests/Parse/ParseBytesTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseBytes;
46
use Parse\ParseObject;
57
use Parse\ParseQuery;
68

7-
require_once 'ParseTestHelper.php';
8-
99
class ParseBytesTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public static function setUpBeforeClass()
1212
{
13-
ParseTestHelper::setUp();
13+
Helper::setUp();
1414
}
1515

1616
public function setUp()
1717
{
18-
ParseTestHelper::clearClass("BytesObject");
18+
Helper::clearClass("BytesObject");
1919
}
2020

2121
public function tearDown()
2222
{
23-
ParseTestHelper::clearClass("BytesObject");
24-
ParseTestHelper::tearDown();
23+
Helper::clearClass("BytesObject");
24+
Helper::tearDown();
2525
}
2626

2727
public function testParseBytesFromArray()

tests/ParseCloudTest.php renamed to tests/Parse/ParseCloudTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseCloud;
46
use Parse\ParseGeoPoint;
57
use Parse\ParseObject;
68

7-
require_once 'ParseTestHelper.php';
8-
9-
class ParseCloudTest extends PHPUnit_Framework_TestCase
9+
class ParseCloudTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public static function setUpBeforeClass()
1212
{
13-
ParseTestHelper::setUp();
13+
Helper::setUp();
1414
}
1515

1616
public function testFunctionsWithObjectParamsFails()

tests/Parse/ParseConfigTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Parse\Test;
4+
5+
use Parse\ParseConfig;
6+
7+
class ParseConfigTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testGetConfig()
10+
{
11+
$config = new ConfigMock();
12+
$this->assertEquals("bar", $config->get("foo"));
13+
$this->assertEquals(1, $config->get("some"));
14+
}
15+
}

tests/ParseFileTest.php renamed to tests/Parse/ParseFileTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?php
22

3+
namespace Parse\Test;
4+
35
use Parse\ParseFile;
46
use Parse\ParseObject;
57
use Parse\ParseQuery;
68

7-
require_once 'ParseTestHelper.php';
8-
99
class ParseFileTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public static function setUpBeforeClass()
1212
{
13-
ParseTestHelper::setUp();
13+
Helper::setUp();
1414
}
1515

1616
public function tearDown()
1717
{
18-
ParseTestHelper::tearDown();
19-
ParseTestHelper::clearClass("TestFileObject");
18+
Helper::tearDown();
19+
Helper::clearClass("TestFileObject");
2020
}
2121

2222
public function testParseFileFactories()
@@ -33,7 +33,8 @@ public function testParseFileFactories()
3333
$this->assertEquals("hi.txt", $file2->getName());
3434
$this->assertTrue(
3535
strpos(
36-
$file3->getData(), 'i am looking for myself'
36+
$file3->getData(),
37+
'i am looking for myself'
3738
) !== false
3839
);
3940
}

0 commit comments

Comments
 (0)