Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created November 12, 2008 10:27
Show Gist options
  • Save speedmax/24131 to your computer and use it in GitHub Desktop.
Save speedmax/24131 to your computer and use it in GitHub Desktop.
<?php
class Describe_context_lookup extends SimpleSpec {
function prepare() {
$this->context = create_context(array(
'location' => (object) array(
'address' => '1st Jones St',
'city' => 'Marry hill', 'state' => 'NSW',
'postcode' => 2320
),
'document' => new Document(
'my business report',
'Since Augest 2005, financial projection has..'
)
));
}
function should_use_dot_to_access_object_property() {
$c = $this->context;
$this->expect($c->resolve(':location.address'))->should_be('1st Jones St');
$this->expect($c->resolve(':document.title'))->should_be('my business report');
}
function should_return_null_for_undefined_or_private_object_property() {
$c = $this->context;
$this->expect($c->resolve(':document.uuid'))->should_be_null(); // Private
$this->expect($c->resolve(':document.undefined_property'))->should_be_null();
}
function should_use_dot_to_perform_method_call() {
$c = $this->context;
$this->expect($c->resolve(':document.to_pdf'))->should_match('/PDF Version :/');
$this->expect($c->resolve(':document.to_xml'))->should_match('/<title>my business report<\/title>/');
}
function should_return_null_for_undefined_or_private_method_call() {
$c = $this->context;
$this->expect($c->resolve(':document._secret'))->should_be_null(); // Private
$this->expect($c->resolve(':document.undefined_method'))->should_be_null();
}
function should_use_dot_to_lookup_additional_array_methods() {
$c = $this->context;
$this->expect($c->resolve(':hobbies.first'))->should_be('football');
$this->expect($c->resolve(':hobbies.last'))->should_be('swimming');
$this->expect($c->resolve(':hobbies.length'))->should_be(3);
$this->expect($c->resolve(':hobbies.size'))->should_be(3);
$this->expect($c->resolve(':numbers.length'))->should_be(9);
}
}
?>
<?php
class Describe_context_lookup extends SimpleSpec {
function should_use_dot_to_access_object_property() {
$c = create_context(array(
'location' => (object) array(
'address' => '1st Jones St',
'city' => 'Marry hill', 'state' => 'NSW',
'postcode' => 2320
),
));
$this[$c->resolve(':location.address')]->should_be('1st Jones St');
$this[$c->resolve(':location.city')]->should_be('Marry hill');
}
function should_return_null_for_undefined_or_private_object_property() {
$c = create_context(array(
'document' => new Document(
'my business report',
'Since Augest 2005, financial projection has..'
)
));
$this[$c->resolve(':document.uuid')]->should_be_null(); // Private
$this[$c->resolve(':document.undefined_property')]->should_be_null();
}
function should_use_dot_to_perform_method_call() {
$c = create_context(array(
'document' => new Document(
'my business report',
'Since Augest 2005, financial projection has..'
)
));
$this[$c->resolve(':document.to_pdf')]->should_match('/PDF Version :/');
$this[$c->resolve(':document.to_xml')]->should_match('/<title>my business report<\/title>/');
}
function should_return_null_for_undefined_or_private_method_call() {
$c = create_context(array(
'document' => new Document(
'my business report',
'Since Augest 2005, financial projection has..'
)
));
$this[$c->resolve(':document._secret')]->should_be_null(); // Private
$this[$c->resolve(':document.undefined_method')]->should_be_null();
}
}
?>
<?php
class Describe_context_lookup extends SimpleSpec {
function prepare() {
$this->context = create_context(array(
'location' => (object) array(
'address' => '1st Jones St',
'city' => 'Marry hill', 'state' => 'NSW',
'postcode' => 2320
),
'document' => new Document(
'my business report',
'Since Augest 2005, financial projection has..'
)
));
}
function should_use_dot_to_access_object_property() {
$c = $this->context;
expects($c->resolve(':location.address'))->should_be('1st Jones St');
expects($c->resolve(':document.title'))->should_be('my business report');
}
function should_return_null_for_undefined_or_private_object_property() {
$c = $this->context;
expects($c->resolve(':document.uuid'))->should_be_null(); // Private
expects($c->resolve(':document.undefined_property'))->should_be_null();
}
function should_use_dot_to_perform_method_call() {
$c = $this->context;
expects($c->resolve(':document.to_pdf'))->should_match('/PDF Version :/');
expects($c->resolve(':document.to_xml'))->should_match('/<title>my business report<\/title>/');
}
function should_return_null_for_undefined_or_private_method_call() {
$c = $this->context;
expects($c->resolve(':document._secret'))->should_be_null(); // Private
expects($c->resolve(':document.undefined_method'))->should_be_null();
}
function should_use_dot_to_lookup_additional_array_methods() {
$c = $this->context;
expects($c->resolve(':hobbies.first'))->should_be('football');
expects($c->resolve(':hobbies.last'))->should_be('swimming');
expects($c->resolve(':hobbies.length'))->should_be(3);
expects($c->resolve(':hobbies.size'))->should_be(3);
expects($c->resolve(':numbers.length'))->should_be(9);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment