|
|
Tue, May. 13th, 2008, 08:25 pm
function serializeDomNodeToXML(node) {
if (node.nodeType == node.TEXT_NODE) {
return node.nodeValue;
}
var ret = '<' + node.nodeName.toLowerCase() + ' ';
if (node.attributes && node.attributes.length) {
for (var i=0, l=node.attributes.length; i<l; i++) {
var attr = node.attributes.item(i);
ret += attr.nodeName + '="' + attr.nodeValue.replace(/"/g,'"') + '" ';
}
}
if (!node.childNodes || !node.childNodes.length) {
ret += '/>';
} else {
ret += '>';
}
for (var i = 0, l = node.childNodes.length; i<l; i++) {
ret += serializeDomNodeToXML(node.childNodes.item(i));
}
if (node.childNodes && node.childNodes.length) {
ret += '</' + node.nodeName.toLowerCase() + '>';
}
console.log(node, ret);
return ret;
}
serializeDomNodeToXML(document.getElementById("js_Menu_siteSelectForm"));
Sat, May. 10th, 2008, 12:38 am Parameter-based stubbing in PHPUnit (not order-based)
1 <?php
2 class PHPUnit_Framework_MockObject_Stub_ParameterBasedAction implements PHPUnit_Framework_MockObject_Stub
3 {
4 private $parameters = array();
5 private $returns = array();
6 private $currentParameters = null;
7
8 public function with()
9 {
10 if (!is_null($this->currentParameters)) {
11 throw new Exception('Out of sequence call - expecting ->will()');
12 }
13
14 $args = func_get_args();
15 $this->currentParameters = new PHPUnit_Framework_MockObject_Matcher_Parameters($args);
16 return $this;
17 }
18
19 public function will($stub)
20 {
21 if (is_null($this->currentParameters)) {
22 throw new Exception('Out of sequence call - expecting ->with()');
23 }
24 if (!($stub instanceof PHPUnit_Framework_MockObject_Stub)) {
25 $stub = new PHPUnit_Framework_MockObject_Stub_Return($stub);
26 }
27 $this->parameters[] = $this->currentParameters;
28 $this->returns[] = $stub;
29 $this->currentParameters = null;
30 return $this;
31 }
32
33 public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
34 {
35 foreach ($this->parameters as $i => $matcher) {
36 if ($matcher->matches($invocation)) {
37 return $this->returns[$i]->invoke($invocation);
38 }
39 }
40 throw new Exception(
41 'No matching parameters found for this invocation: '
42 . PHPUnit_Util_Type::toString($invocation)
43 );
44 }
45
46 public function toString()
47 {
48 return 'not implemented yet';
49 }
50 }
51
52 class TestFactory
53 {
54 public function getImplementation($className)
55 {
56 }
57 }
58
59 class TestTest extends PHPUnit_Framework_TestCase
60 {
61 public function testParameterBasedAction()
62 {
63 $factory = $this->getMock('TestFactory');
64 $obj = new stdClass;
65 $obj2 = new stdClass;
66 $factory->expects($this->any())
67 ->method('getImplementation')
68 ->will(
69 $this->parameterBased()
70 ->with('obj1')->will($obj)
71 ->with('obj2')->will($this->returnValue($obj2))
72 ->with('qq')->will($this->throwException(new Exception('test exception')))
73 );
74 $this->assertSame($obj, $factory->getImplementation('obj1'));
75 $this->assertSame($obj2, $factory->getImplementation('obj2'));
76 $this->assertSame($obj, $factory->getImplementation('obj1'));
77 try {
78 $factory->getImplementation('qq');
79 $this->fail('Should have thrown exception');
80 } catch (Exception $e) {
81 // passes
82 }
83 }
84 public function parameterBased()
85 {
86 return new PHPUnit_Framework_MockObject_Stub_ParameterBasedAction;
87 }
88 }
89 ?>
| |
Fri, Apr. 25th, 2008, 09:35 pm

- Сегодня нельзя мыться. - Почему? - Горячей воды нет. Sat, Mar. 15th, 2008, 11:40 pm
Fri, Feb. 22nd, 2008, 11:43 pm Beware the Jabberwock, my son...
Wed, Feb. 20th, 2008, 02:50 pm
1 <?php
2 function save_context($no, $str, $file, $line, $context) {
3 var_dump("saving context", $context);
4 file_put_contents("q.context", serialize($context));
5 }
6 set_error_handler("save_context");
7
8 function restorable() {
9 if (file_exists("q.context")) {
10 extract(unserialize(file_get_contents("q.context")));
11 var_dump("restored $a $b");
12 unlink("q.context");
13 } else {
14 var_dump("new run");
15 $a = rand();
16 $b = rand();
17 trigger_error("save_context");
18 }
19 }
20 restorable();
| |
Sat, Feb. 16th, 2008, 10:03 pm Free not as in beer

Вот ведь что интересно - циркулирует мысль, что использование опенсурсного софта (программ/библиотек) сокращает время разработки и удешевляет ее. Так почему, нет, блять, ПОЧЕМУ просматривая историю времязатрат по проекту я вижу, что дешевле было написать свой инсталлятор, чем адаптировать PEAR к промышленному использованию? Почему в субботний вечер до десяти часов я сижу и фикшу баги в Phing'е, разработчики которого, видите ли, не признают симлинки и не умееют их копировать? Бесплатно, говорите? Расскажете психиатру. Tue, Feb. 12th, 2008, 04:23 am Алтан Ураг
Sat, Dec. 29th, 2007, 08:51 pm Last Friday of 2007 - Party
Thu, Dec. 27th, 2007, 12:27 am 16 метров не помеха
Sat, Dec. 22nd, 2007, 01:26 pm Подарочный гобот
Thu, Dec. 20th, 2007, 04:07 pm

Там человек-микрофон с серпантином на ушах ходит Thu, Dec. 13th, 2007, 08:37 pm
Tue, Dec. 11th, 2007, 01:12 am

Выпустил таки jabber bot'а, мониторящего svn: http://svnbot.googlecode.com/. За полчаса пресс-релиз оказался на первом месте в гугле по запросу 'jabber svn bot' - мелочь, а приятно.
Sat, Dec. 8th, 2007, 12:44 am
Короткое — это хорошо порезанное длинное
Fri, Dec. 7th, 2007, 05:56 pm
There were no screams. There was no time. The mountain called monkey had spoken. There was only fire. And then, nothing...
Gorillaz
Thu, Dec. 6th, 2007, 01:01 am
Thu, Nov. 22nd, 2007, 08:19 pm
Tue, Nov. 20th, 2007, 02:38 am
|