Skip to content

Instantly share code, notes, and snippets.

View cakephp-tutorial's full-sized avatar

CakePHP Italia Tutorial cakephp-tutorial

View GitHub Profile
<?php
#file /app/Model/Contact.php
public function getAllContacts() {
return $this->find('all');
}
<?php
#file /app/Test/Case/Model/ContactTest.php
public function testGetAllContacts() {
//prendo i records dal modello
$result = $this->Contact->getAllContacts();
//questo è il risultato che mi aspetto
$exptected = array(
array('Contact' => array('id' => 1, 'name' => 'Walter', 'surname' => 'Raponi') ),
<?php
#file /app/Test/Case/Model/ContactTest.php
App::uses('Contact', 'Model');
class ContactTest extends CakeTestCase {
public $fixtures = array('app.contact');
public function setup() {
parent::setup();
$this->Contact = ClassRegistry::init('Contact');
}
<?php
#file /app/Test/Fixture/ContactFixture.php
class ContactFixture extends CakeTestFixture {
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
'surname' => array('type' => 'string', 'null' => false),
);
public $records = array(
array('id' => 1, 'name' => 'Walter', 'surname' => 'Raponi' ),
CREATE TABLE `phonetags` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`phonetag` VARCHAR(200) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `mailtags` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`mailtag` VARCHAR(200) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakephp',
'password' => 'cakephp',
'database' => 'cakephp_test',
<?php
class AppController extends Controller {
public $components = array('DebugKit.Toolbar');
}
<?php
CakePlugin::load('DebugKit');
git clone --single-branch --branch 2.2 git://github.com/cakephp/debug_kit.git DebugKit
git submodule add --branch 2.2 git://github.com/cakephp/debug_kit.git Plugin/DebugKit
git submodule init
git submodule update