Skip to content

Commit e7e6a12

Browse files
committed
Minor fix: Plural Model names convention
1 parent 683e19e commit e7e6a12

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

en/auth/simple-auth-user.wiki

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ Create this file in `controllers/UsersController`:
4949
namespace app\controllers;
5050

5151
use lithium\security\Auth;
52-
use app\models\User;
52+
use app\models\Users;
5353

5454
class UsersController extends \lithium\action\Controller {
5555

5656
public function index() {
57-
$users = User::all();
57+
$users = Users::all();
5858
return compact('users');
5959
}
6060

6161
public function add() {
62-
$user = User::create($this->request->data);
62+
$user = Users::create($this->request->data);
6363

6464
if (($this->request->data) && $user->save()) {
6565
return $this->redirect('Users::index');
@@ -96,4 +96,4 @@ Then create the templates.
9696
<li><?=$user->username; ?></li>
9797
<?php } ?>
9898
</ul>
99-
}}}
99+
}}}

en/quality-code/testing.wiki

+20-22
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ Let's start out by creating a simple test case as a working example. Our first w
1818

1919
{{{
2020
$ cd /path/to/lithium/app
21-
$ li3 create model Post
21+
$ li3 create model Posts
2222

23-
Post created in app\models.
23+
Posts created in app\models.
2424
}}}
2525

2626
We can also use the `li3 create` command to create our test case class.
2727

2828
{{{
29-
$ li3 create test model Post
29+
$ li3 create test model Posts
3030

31-
PostTest created for Post in app\tests\cases\models.
31+
PostsTest created for Posts in app\tests\cases\models.
3232
}}}
3333

3434
Doing so creates a test file template class that extends `lithium\test\Unit` and looks like the following:
@@ -38,9 +38,9 @@ Doing so creates a test file template class that extends `lithium\test\Unit` and
3838

3939
namespace app\tests\cases\models;
4040

41-
use app\models\Post;
41+
use app\models\Posts;
4242

43-
class PostTest extends \lithium\test\Unit {
43+
class PostsTest extends \lithium\test\Unit {
4444

4545
public function setUp() {}
4646

@@ -53,7 +53,7 @@ class PostTest extends \lithium\test\Unit {
5353

5454
The two initial methods supplied act as they're named. The `setUp()` method is used to perform any preparation work you'll need to perform your unit testing logic. This might be anything from setting up database connections to initializing mock data. Similarly, `tearDown()` is used to clean up anything that might be left over once a unit test has been completed. These methods are called before and after each method in your unit test case.
5555

56-
The meat of the unit test, however, will be housed inside of methods you create. Each piece of your unit testing logic should be placed inside of a method whose name starts with 'test'. Before we make any adjustments to the `Post` model, let's exercise a bit of TDD and write an example test method first.
56+
The meat of the unit test, however, will be housed inside of methods you create. Each piece of your unit testing logic should be placed inside of a method whose name starts with 'test'. Before we make any adjustments to the `Posts` model, let's exercise a bit of TDD and write an example test method first.
5757

5858
Since our test case is a subclass of `lithium\test\Unit`, we have easy access to a number of methods that help us validate test assertions. Since they're plainly named, I'll list some here. For for information, please refer to the API documentation for `lithium\test\Unit`.
5959

@@ -69,31 +69,31 @@ Since our test case is a subclass of `lithium\test\Unit`, we have easy access to
6969
- `assertCookie()`
7070
- `expectException()`
7171
72-
Every post should have a great title, and any editor knows that post titles containing the phrase "top ten" are pure rubbish. We'll eventually need a method in our Post model that searches for this phrase and warns us. Before writing that method, let's establish a test case to cover it. We'll call it `testIsGoodTitle()`. See an example implementation below:
72+
Every post should have a great title, and any editor knows that post titles containing the phrase "top ten" are pure rubbish. We'll eventually need a method in our Posts model that searches for this phrase and warns us. Before writing that method, let's establish a test case to cover it. We'll call it `testIsGoodTitle()`. See an example implementation below:
7373

7474
{{{
7575
<?php
7676

7777
namespace app\tests\cases\models;
7878

79-
use app\models\Post;
79+
use app\models\Posts;
8080

81-
class PostTest extends \lithium\test\Unit {
81+
class PostsTest extends \lithium\test\Unit {
8282

8383
public function setUp() {}
8484

8585
public function tearDown() {}
8686

8787
public function testIsGoodTitle() {
88-
$this->assertTrue(Post::isGoodTitle("How to Win Friends and Influence People"));
89-
$this->assertFalse(Post::isGoodTitle("The Top 10 Best Top Ten Lists"));
88+
$this->assertTrue(Posts::isGoodTitle("How to Win Friends and Influence People"));
89+
$this->assertFalse(Posts::isGoodTitle("The Top 10 Best Top Ten Lists"));
9090
}
9191
}
9292

9393
?>
9494
}}}
9595

96-
Turn back to your browser showing the Unit Test Dashboard, and refresh it. You should see a new entry at the top of the list on the left hand side that shows our `PostTest` unit test case. Clicking on the `PostTest` test case should show you the test results. At this point you won't get far—the model will likely complain about a missing connection or function: as it should!
96+
Turn back to your browser showing the Unit Test Dashboard, and refresh it. You should see a new entry at the top of the list on the left hand side that shows our `PostsTest` unit test case. Clicking on the `PostsTest` test case should show you the test results. At this point you won't get far—the model will likely complain about a missing connection or function: as it should!
9797

9898
Let's start working on the model so we can get that test to pass. First, let's specify our model as not having any connection. We'll adjust this later, but let's do this now for simplicity's sake.
9999

@@ -102,7 +102,7 @@ Let's start working on the model so we can get that test to pass. First, let's s
102102

103103
namespace app\models;
104104

105-
class Post extends \lithium\data\Model {
105+
class Posts extends \lithium\data\Model {
106106
protected $_meta = array('connection' => false);
107107
public $validates = array();
108108
}
@@ -117,7 +117,7 @@ Once that's in place, running the test again should have it barking about how `i
117117

118118
namespace app\models;
119119

120-
class Post extends \lithium\data\Model {
120+
class Posts extends \lithium\data\Model {
121121
protected $_meta = array('connection' => false);
122122
public $validates = array();
123123

@@ -135,9 +135,9 @@ At this point, your test cases should run successfully in the Unit Test Dashboar
135135
136136
Mocks are used in place of actual sources of information. You can create a mock for just about anything: a data source, model data, a console command response... anything. Since we're dealing primarily with the model in this example, let's continue that train of thought, and use some mocks to help us test our new model functionality.
137137

138-
Let's create a MockPost that returns test data we can use to run through our `isGoodTitle()` method. One easy way to do that is to create a new class that just returns a RecordSet (in the case of an SQL database) or a Document (in the case of a document database) collection.
138+
Let's create a MockPosts that returns test data we can use to run through our `isGoodTitle()` method. One easy way to do that is to create a new class that just returns a RecordSet (in the case of an SQL database) or a Document (in the case of a document database) collection.
139139

140-
Start by creating a new file in `app/tests/mocks/data/MockPost.php`:
140+
Start by creating a new file in `app/tests/mocks/data/MockPosts.php`:
141141

142142
{{{
143143

@@ -147,7 +147,7 @@ namespace app\tests\mocks\data;
147147

148148
use lithium\data\collection\RecordSet;
149149

150-
class MockPost extends \app\models\Post {
150+
class MockPosts extends \app\models\Posts {
151151
public static function find($type = 'all', array $options = array()) {
152152
switch ($type) {
153153
case 'first':
@@ -174,15 +174,13 @@ What we've got here is essentially a model that spits out hard-coded data when w
174174
{{{
175175

176176
public function testMockTitles() {
177-
$results = MockPost::find('all');
177+
$results = MockPosts::find('all');
178178

179179
$first = $results->current();
180-
$this->assertFalse(MockPost::isGoodTitle($first['title']));
180+
$this->assertFalse(MockPosts::isGoodTitle($first['title']));
181181
}
182182

183183
}}}
184184

185185
Head back to the Unit Test Dashboard to make sure this runs successfully, and you're done!
186186

187-
188-

0 commit comments

Comments
 (0)