root/events/phpframework/piece_framework/trunk/specs/Phwittr/SpecCommon.php @ 14093

Revision 14093, 4.2 kB (checked in by kumatch, 6 years ago)

Added specs afterAll().

  • Property svn:keywords set to Id Rev
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4/*
5 * PHP versions 5
6 *
7 * @package    Phwittr_PieceFramework
8 * @copyright  2008 KUMAKURA Yousuke All rights reserved.
9 * @version    SVN: $Id$
10 * @since      File available since Release 0.1.0
11 */
12
13require_once 'Phwittr/Config.php';
14require_once 'Piece/ORM.php';
15require_once 'Piece/ORM/Context.php';
16require_once 'Piece/ORM/Mapper/Factory.php';
17require_once 'Cache/Lite.php';
18
19// {{{ SpecCommon
20
21/**
22 * SpecCommon - Phwittr Spec のための基底クラス
23 *
24 * @package    Phwittr_PieceFramework
25 * @copyright  2008 KUMAKURA Yousuke All rights reserved.
26 * @version    Release: @package_version@
27 * @since      Class available since Release 0.1.0
28 */
29class SpecCommon extends PHPSpec_Context
30{
31
32    // {{{ properties
33
34    /**#@+
35     * @access public
36     */
37
38    /**#@-*/
39
40    /**#@+
41     * @access protected
42     */
43
44    /**#@-*/
45
46    /**#@+
47     * @access private
48     */
49
50    /**#@-*/
51
52    /**#@+
53     * @access public
54     */
55
56    public function beforeAll()
57    {
58        Phwittr_Config::configurePieceORM('phwittr_test');
59        $this->_cacheDirectory = dirname(__FILE__) . '/../../cache/orm';
60        $this->after();
61
62        $this->_foo = new stdClass();
63        $this->_foo->userName = 'foo';
64        $this->_foo->email    = 'foo@example.com';
65        $this->_foo->password = 'foopassword';
66        $this->_foo->key = sha1('fookey');
67        $this->_foo->flag = 1;
68
69        $this->_bar = new stdClass();
70        $this->_bar->userName = 'bar';
71        $this->_bar->email    = 'bar@example.com';
72        $this->_bar->password = 'barpassword';
73        $this->_bar->key = sha1('barkey');
74        $this->_bar->flag = 1;
75
76        $this->_baz = new stdClass();
77        $this->_baz->userName = 'baz';
78        $this->_baz->email    = 'baz@example.com';
79        $this->_baz->password = 'bazpassword';
80        $this->_baz->key = sha1('bazkey');
81        $this->_baz->flag = 1;
82    }
83
84    public function before()
85    {
86        Phwittr_Config::configurePieceORM('phwittr_test');
87    }
88
89    public function after()
90    {
91        $mapper = Piece_ORM::getMapper('Users');
92        $mapper->executeQuery("truncate followers");
93        $mapper->executeQuery("truncate users");
94        $mapper->executeQuery("truncate statuses");
95
96        $GLOBALS['PIECE_ORM_Configured'] = false;
97        Piece_ORM_Context::clear();
98        Piece_ORM_Mapper_Factory::clearInstances();
99
100        $cache = new Cache_Lite_File(array('cacheDir' => "{$this->_cacheDirectory}/",
101                                           'masterFile' => '',
102                                           'automaticSerialization' => true,
103                                           'errorHandlingAPIBreak' => true)
104                                     );
105        $cache->clean();
106    }
107
108    public function afterAll() {}
109
110    /**#@-*/
111
112    /**#@+
113     * @access protected
114     */
115
116    protected function _createUserRecord(&$context)
117    {
118        $user = Piece_ORM::createObject('Users');
119        $user->userName = $context->userName;
120        $user->email = $context->email;
121        $user->password = sha1($context->password);
122        $user->registrationKey = $context->key;
123
124        $mapper = Piece_ORM::getMapper('Users');
125        $mapper->insert($user);
126
127        $user->registrationFlag = $context->flag;
128        $mapper->update($user);
129    }
130
131    protected function _createFollowerRecord($userId, $followId)
132    {
133        $follower = Piece_ORM::createObject('Followers');
134        $follower->userId = $userId;
135        $follower->followId = $followId;
136
137        $mapper = Piece_ORM::getMapper('Followers');
138        $mapper->insert($follower);
139    }
140
141    protected function _createStatusRecord($userId, $replyId, $comment)
142    {
143        $status = Piece_ORM::createObject('Statuses');
144        $status->userId = $userId;
145        $status->replyUserId = $replyId;
146        $status->comment = $comment;
147
148        $mapper = Piece_ORM::getMapper('Statuses');
149        $mapper->insert($status);
150    }
151
152    /**#@-*/
153
154    /**#@+
155     * @access private
156     */
157
158    /**#@-*/
159
160    // }}}
161}
162
163// }}}
164
165/*
166 * Local Variables:
167 * mode: php
168 * coding: utf-8
169 * tab-width: 4
170 * c-basic-offset: 4
171 * c-hanging-comment-ender-p: nil
172 * indent-tabs-mode: nil
173 * End:
174 */
175?>
Note: See TracBrowser for help on using the browser.